Parsing bug
philip-nicholls opened this issue · 2 comments
philip-nicholls commented
test.csv
"A", "1"
"2", "B"
"C", "D"
parse.js
let inputStream = fs.createReadStream(__dirname + '/test.csv', 'utf8');
inputStream
.pipe(new CsvReadableStream())
.on('data', function (row) {
console.log("DATA", row);
})
.on('end', function () {
console.log("END");
})
.on('error', function (e) {
reject(e);
});
Output
DATA [ 'A', ' "1"' ]
DATA [ '2', ' "B"' ]
DATA [ 'C', ' "D"' ]
END
Your parser doesn't like whitespace between the columns.
yeya commented
danielgindi commented
This parser behaves like Excel, right, but it is only because this is the correct behavior. Other behaviors would create unpredictable results.
This is a comma separated file, not "comma and space separated".
Now when there are special characters, we need to put the value in quotes.
And quotes could appear inside a value.
Imagine a value that begins with a space and a quote... That's just a standard value, unwrapped.
Btw, I have never seen any piece of software create csvs with spaces after the commas.