-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty trailing fields populated with indexes after resuming a paused parser, loses place #985
Comments
It should be fixed with 824bbd9 |
I replaced the package dependency with the new file from The odd thing is that, in addition to the underscore indices appearing, it looks like the parser is losing its place. Fields are getting eaten and the results are shifting left. |
Please provide a simple example that we can run on our test suite. |
I don't have a lot of Node experience (I'm a front-end developer 🤷♂️) but below is a new entry for the {
description: "Pause and resume works with headers and empty trailing fields (Regression Test for Bug #985)",
expected: [["Column 1", "Column 2", "Column 3", "Column 4", "Column 5"], [
{ "Column 1": "R1C1", "Column 2": "", "Column 3": "R1C3", "Column 4": "", "Column 5": "" },
{ "Column 1": "R2C1", "Column 2": "", "Column 3": "", "Column 4": "", "Column 5": "" },
{ "Column 1": "R3C1", "Column 2": "", "Column 3": "", "Column 4": "R3C4", "Column 5": "" },
{ "Column 1": "R4C1", "Column 2": "", "Column 3": "", "Column 4": "", "Column 5": "" },
]],
run: function(callback) {
var inputString = [
"Column 1,Column 2,Column 3,Column 4,Column 5",
"R1C1,,R1C3,,",
"R2C1,,,,",
"R3C1,,,R3C4,",
"R4C1,,,,"
].join("\n");
var output = [];
var dataRows = [];
var headers = null;
Papa.parse(inputString, {
header: true,
step: function(results, parser) {
if (results)
{
if (!headers) {
headers = results.meta.fields;
}
parser.pause();
parser.resume();
if (results.data) {
dataRows.push(results.data);
}
}
},
complete: function() {
output.push(headers);
output.push(dataRows);
callback(output);
}
});
}
}, |
(Also, since I haven't collaborated yet I can't reopen this on my own.) |
I was able to confirm that this only occurs when headers are requested. |
I think I found the cause of this. The first issue is how The second issue is how the headers are modified if duplicates are found at lines 1497-1501. If duplicates are found, indexes are appended, but when the first input line is reinserted into The result of this is that It feels to me like it might make more sense to directly check for preexisting headers, rather than rely on Instead of populating
I think this would prevent Does this make sense? I wanted to run this by you before making a PR, but I think I could put this together tomorrow. |
As I'm building this, I'm seeing how |
(I got excited and created the PR anyways. 😁 ) |
having this same issue. but does this on default... in the csv there I just empty commas ",,,,," like that and they get auto filled with _1 _2 etc.... |
This is still happening with 5.4.1. I get empty values that are populated with |
When using
parser.pause()
/parser.resume()
, after resuming the parser, trailing empty cells in the row returned bystep
have"_1"
,"_2"
,"_3"
etc. instead of empty cells. Thereafter, parsing appears to hit wrong locations.Code sandbox here:
https://codesandbox.io/s/heuristic-violet-8wrinv?file=/src/CSVParser.js
The text was updated successfully, but these errors were encountered: