node-csv-stream icon indicating copy to clipboard operation
node-csv-stream copied to clipboard

Issue when escape characters are split over stream chunks

Open alirussell opened this issue 6 years ago • 0 comments

Hi,

im running into an issue where an escape then the following enclose character (both in my case a double quote "), are split over two sequential chunks in a stream..

In this simple bit of code for example:

var Parser = require('csv-stream/lib/parser');

var p = new Parser({
    escapeChar : '"',
    enclosedChar : '"'
});

p.parse('"..."');
p.parse('"quoted"""');

the full string is actually "...""quoted""", but because the two characters are split, it breaks this line (https://github.com/lbdremy/node-csv-stream/blob/master/lib/parser.js#L52) because it doesn't have access to the next character in the full string to determine if its actually an enclose character.

A suggested fix would be to keep track of if we are currently "escaping" between chunks, and treat the first character of the next chunk a bit differently.

I will create a PR for the fix

Thanks

alirussell avatar Mar 19 '18 18:03 alirussell