Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/csv2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const Csv2Json = function(options) {
stateVariables.insideWrapDelimiter = false;
stateVariables.parsingValue = false;
// Next iteration will substring, add the value to the line, and push the line onto the array of lines
} else if (character === options.delimiter.wrap && (index === 0 || utils.getNCharacters(csv, index - 1, eolDelimiterLength) === options.delimiter.eol)) {
} else if (character === options.delimiter.wrap && (index === 0 || utils.getNCharacters(csv, index - eolDelimiterLength, eolDelimiterLength) === options.delimiter.eol)) {
// If the line starts with a wrap delimiter (ie. "*)

stateVariables.insideWrapDelimiter = true;
Expand Down
3 changes: 2 additions & 1 deletion test/config/testCsvFilesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const fs = require('fs'),
{key: 'unwindEmptyArray', file: '../data/csv/unwindEmptyArray.csv'},
{key: 'unwindWithSpecifiedKeys', file: '../data/csv/unwindWithSpecifiedKeys.csv'},
{key: 'localeFormat', file: '../data/csv/localeFormat.csv'},
{key: 'invalidParsedValues', file: '../data/csv/invalidParsedValues.csv'}
{key: 'invalidParsedValues', file: '../data/csv/invalidParsedValues.csv'},
{key: 'firstColumnWrapCRLF', file: '../data/csv/firstColumnWrapCRLF.csv'}
];

function readCsvFile(filePath) {
Expand Down
3 changes: 2 additions & 1 deletion test/config/testJsonFilesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ module.exports = {
unwind: require('../data/json/unwind'),
unwindEmptyArray: require('../data/json/unwindEmptyArray'),
localeFormat: require('../data/json/localeFormat'),
invalidParsedValues: require('../data/json/invalidParsedValues')
invalidParsedValues: require('../data/json/invalidParsedValues'),
firstColumnWrapCRLF: require('../data/json/firstColumnWrapCRLF.json')
};
11 changes: 11 additions & 0 deletions test/csv2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ function runTests(jsonTestData, csvTestData) {
});
});

// Test case for #153
it('should wrap first column with crlf line break', (done) => {
converter.csv2json(csvTestData.firstColumnWrapCRLF, (err, json) => {
if (err) done(err);
json.should.deepEqual(jsonTestData.firstColumnWrapCRLF);
done();
}, {
delimiter: { eol: '\r\n' }
});
});

it('should strip the excel byte order mark character, if specified, and convert to json', (done) => {
converter.csv2json(csvTestData.excelBOM, (err, json) => {
if (err) done(err);
Expand Down
2 changes: 2 additions & 0 deletions test/data/csv/firstColumnWrapCRLF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
column 1,column 2,column 3
"A,B","C,D","E,F"
1 change: 1 addition & 0 deletions test/data/json/firstColumnWrapCRLF.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ { "column 1": "A,B", "column 2": "C,D", "column 3": "E,F" } ]