Skip to content

Commit

Permalink
Merge pull request #106 from toddbluhm/space-parsing-fix
Browse files Browse the repository at this point in the history
Fix for when chunk returned by transform to the parser ends with a space
  • Loading branch information
dustinsmith1024 committed Mar 31, 2016
2 parents af1e0bc + c6bf5ef commit 6aec5c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function createParser(options) {
token = nextToken.token;
if (isUndefinedOrNull(token)) {
i = lastLineI;
cursor = null;
break;
} else if (ROW_DELIMITER.test(token)) {
i = nextToken.cursor + 1;
Expand Down
12 changes: 11 additions & 1 deletion test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ it.describe("fast-csv parser", function (it) {
});
});

it.should("not parse a row if there is a trailing delimiter with a space, and there is more data", function () {
var data = "first_name,last_name,email_address, ";
var myParser = parser({delimiter: ","});
var parsedData = myParser(data, true);
assert.deepEqual(parsedData, {
"line": "first_name,last_name,email_address, ",
"rows": []
});
});

it.should("parse a row if a new line is found and there is more data", function () {
var data = "first_name,last_name,email_address\n";
var myParser = parser({delimiter: ","});
Expand Down Expand Up @@ -767,4 +777,4 @@ it.describe("fast-csv parser", function (it) {
});
});

});
});

0 comments on commit 6aec5c2

Please sign in to comment.