Skip to content
Open
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
8 changes: 8 additions & 0 deletions papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,14 @@ License: MIT
}


// When streaming, a closing quote with no further newline left in this
// chunk means the row is still incomplete -- most likely a delimiter or
// newline split across the chunk boundary (e.g. a "\r\n" cut right after
// the "\r"). Defer the row to the next chunk instead of reporting a
// spurious malformed-quote error. (#1103)
if (ignoreLastRow && nextNewline === -1)
return finish();

// Checks for valid closing quotes are complete (escaped quotes or quote followed by EOF/delimiter/newline) -- assume these quotes are part of an invalid text string
errors.push({
type: 'Quotes',
Expand Down
25 changes: 25 additions & 0 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,31 @@ var CUSTOM_TESTS = [
});
}
},
{
description: "Quoted field with \\r\\n line ending split across a chunk boundary does not emit a spurious InvalidQuotes error (#1103)",
expected: [[['a', 'bc'], ['d', 'ef']], []],
run: function(callback) {
var data = [];
var errors = [];
// chunkSize 9 makes the first chunk end on the "\r" of the first "\r\n",
// splitting the line ending across the chunk boundary. The closing quote of
// "bc" is then followed only by a lone "\r" (neither a delimiter nor a full
// newline), which previously tripped a false "Trailing quote on quoted field
// is malformed" error even though the row is simply incomplete.
Papa.parse('"a","bc"\r\n"d","ef"', {
delimiter: ',',
newline: '\r\n',
chunkSize: 9,
chunk: function(results) {
data = data.concat(results.data);
errors = errors.concat(results.errors);
},
complete: function() {
callback([data, errors]);
}
});
}
},
{
description: "Step is called for each row",
expected: 2,
Expand Down