Skip to content

Commit e25121f

Browse files
authored
Merge pull request #154 from pustovitDmytro/stable
Handle wrap in first column for multiline eol (#153)
2 parents 0155b47 + 225a202 commit e25121f

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

src/csv2json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const Csv2Json = function(options) {
148148
stateVariables.insideWrapDelimiter = false;
149149
stateVariables.parsingValue = false;
150150
// Next iteration will substring, add the value to the line, and push the line onto the array of lines
151-
} else if (character === options.delimiter.wrap && (index === 0 || utils.getNCharacters(csv, index - 1, eolDelimiterLength) === options.delimiter.eol)) {
151+
} else if (character === options.delimiter.wrap && (index === 0 || utils.getNCharacters(csv, index - eolDelimiterLength, eolDelimiterLength) === options.delimiter.eol)) {
152152
// If the line starts with a wrap delimiter (ie. "*)
153153

154154
stateVariables.insideWrapDelimiter = true;

test/config/testCsvFilesList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const fs = require('fs'),
3333
{key: 'unwindEmptyArray', file: '../data/csv/unwindEmptyArray.csv'},
3434
{key: 'unwindWithSpecifiedKeys', file: '../data/csv/unwindWithSpecifiedKeys.csv'},
3535
{key: 'localeFormat', file: '../data/csv/localeFormat.csv'},
36-
{key: 'invalidParsedValues', file: '../data/csv/invalidParsedValues.csv'}
36+
{key: 'invalidParsedValues', file: '../data/csv/invalidParsedValues.csv'},
37+
{key: 'firstColumnWrapCRLF', file: '../data/csv/firstColumnWrapCRLF.csv'}
3738
];
3839

3940
function readCsvFile(filePath) {

test/config/testJsonFilesList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ module.exports = {
2525
unwind: require('../data/json/unwind'),
2626
unwindEmptyArray: require('../data/json/unwindEmptyArray'),
2727
localeFormat: require('../data/json/localeFormat'),
28-
invalidParsedValues: require('../data/json/invalidParsedValues')
28+
invalidParsedValues: require('../data/json/invalidParsedValues'),
29+
firstColumnWrapCRLF: require('../data/json/firstColumnWrapCRLF.json')
2930
};

test/csv2json.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ function runTests(jsonTestData, csvTestData) {
308308
});
309309
});
310310

311+
// Test case for #153
312+
it('should wrap first column with crlf line break', (done) => {
313+
converter.csv2json(csvTestData.firstColumnWrapCRLF, (err, json) => {
314+
if (err) done(err);
315+
json.should.deepEqual(jsonTestData.firstColumnWrapCRLF);
316+
done();
317+
}, {
318+
delimiter: { eol: '\r\n' }
319+
});
320+
});
321+
311322
it('should strip the excel byte order mark character, if specified, and convert to json', (done) => {
312323
converter.csv2json(csvTestData.excelBOM, (err, json) => {
313324
if (err) done(err);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
column 1,column 2,column 3
2+
"A,B","C,D","E,F"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ { "column 1": "A,B", "column 2": "C,D", "column 3": "E,F" } ]

0 commit comments

Comments
 (0)