Fixed an issue where copying and pasting a cell with multiple line data

will result in multiple rows. Fixes #5526

Fixed an old issue where quotes are not escaped when copying the cells.
As per CSV standards, if the string is in double quotes and there are
double quotes inside the string then they should be escaped with extra double-quotes.
This commit is contained in:
Aditya Toshniwal
2020-08-10 16:53:32 +05:30
committed by Akshay Joshi
parent 9d006d0ec5
commit 26a758a0d6
5 changed files with 101 additions and 13 deletions

View File

@@ -7,7 +7,8 @@
//
//////////////////////////////////////////////////////////////
import { getEpoch, getGCD, getMod, quote_ident, parseFuncParams, getRandomInt, sprintf } from 'sources/utils';
import { getEpoch, getGCD, getMod, quote_ident, parseFuncParams,
getRandomInt, sprintf, CSVToArray } from 'sources/utils';
describe('getEpoch', function () {
it('should return non zero', function () {
@@ -168,3 +169,25 @@ describe('sprintf', function () {
);
});
});
describe('CSVToArray', function() {
it('simple input single record', function() {
expect(CSVToArray('a,b')).toEqual([['a', 'b']]);
});
it('simple input delimeter change', function() {
expect(CSVToArray('"a";"b"', ';')).toEqual([['a', 'b']]);
});
it('simple input multi records', function() {
expect(CSVToArray('"a","b"\n"c","d"')).toEqual([['a', 'b'], ['c', 'd']]);
});
it('multiline input containing double quotes', function() {
expect(CSVToArray('"hello ""a\nb""","c"')).toEqual([['hello "a\nb"','c']]);
});
it('multiline input containing single quotes', function() {
expect(CSVToArray('\'hello \'\'a\nb\'\'\',\'c\'', ',', '\'')).toEqual([['hello \'a\nb\'','c']]);
});
});