C2FO/fast-csv — pull request #17 by ovmjm (2013-10-15 16:52:53+00:00)
Title: Fix missed line splits

The CSV data is currently read this way

var lines = "", parse = this._parse.bind(this), end = this.emit.bind(this, "end");
from.on("data", function streamOnData(data) {
var lineData = (lines + data).trim().split(LINE_SPLIT);
if (lineData.length > 1) {
lines = lineData.pop();
parse(lineData);
} else {
lines += data;
}
});

The `trim()` call causes some line splits to be missed when `(lines + data)` contains at least one `\n` and ends by another `\n`. In this case the split will produce two parts and the last `\n` will be lost in `lines` (from the `pop`) and the next iteration will try to parse a line which is the concatenation of two, most of the time ending in a validation error when lucky and wrong data otherwise.

Here is a [fiddle](http://jsfiddle.net/4uqPS/1/) that emulates the process, reproduces the bug and show the details of the successives iterations assuming chunks of 10 bytes (node buffers are actually 65535 bytes long so the problem only rarely happens for huge CSV files).

The pull request provided just get rid of the `trim()`, works for us, but might be other solutions.