-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Generate headers in Parser
, based upon presence of _fields
, without changing _input
(fixes issue #985)
#989
base: master
Are you sure you want to change the base?
Conversation
I *think* this is the last commit I have. Sigh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to existing tests were required to reflect that:
Parser
now requires an array as its second argument for its constructorParser.parse()
no longer returns the header row as data
🎉 |
Hey @landisdesign Can't thank you enough. PapaParse basically didn't work from in a stream pipeline without this. You are a life saver. |
@mholt is there a different plan to resolve this issue? it seems quite pressing and this pr seems to resolve it nicely. |
As long as it works, and the tests pass, this is OK with me -- will probably defer to @pokoli for a closer look though. Ping me again if it isn't merged in a while. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes also look good to me, I added some comments to simplify the the tests a little bit. Could you have a look at it?
tests/test-cases.js
Outdated
@@ -2018,6 +2027,51 @@ describe('Unparse Tests', function() { | |||
|
|||
|
|||
var CUSTOM_TESTS = [ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add new tests at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! Done.
tests/test-cases.js
Outdated
{ | ||
description: "Pause and resume works with headers and duplicate fields (Regression Test for Bug #985)", | ||
expected: [[ | ||
["Column 1", "Column 2", "Column 3", "Column 4", "Column 5"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to have 5 rows? Can we make the test simpler with less rows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not. I reduced it to two rows and four columns, enough to make sure we could test column value duplicates and that the headers didn't shift between pause/resume stages.
tests/test-cases.js
Outdated
step: function(results, parser) { | ||
if (results) | ||
{ | ||
headerResults.push(results.meta.fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pusshing headers multiple times? Won't be better to just push when empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to double-check that multiple passes returned the same headers. It looked like the original code could have updated the headers on each pass, which seemed problematic. Perhaps that question makes sense as a separate test, or do you think it isn't worth the check?
This lets us test duplicates in first row
Fixes issue #985.
Previously, headers were created in
ParseHandle
'sprocessResults()
, but also managed byParser.parse()
whenbaseIndex
was falsy.When headers were requested and
baseIndex
was false,parse()
would modify_input
without adjustingcursor
, causing the parser to mistake where it needed to continue parsing. This would cause further rows to be shifted. In addition,baseIndex
could beundefined
or0
, depending on how it was called, causing thiscursor
shift to potentially happen twice.This PR:
_fields
based upon the value of_results.meta.fields
without changing_input
_fields.length
as the source of truth for whether or not headers should be generated whenconfig.header
is truthyParser
by passing_fields
to theParser
constructor where the above test is performedfields
to results generated byParser.parse()
based upon whether or not headers are availableAdditional impacts:
pushRow()
, the header row is no longer returned as data byParser.parse()
. Instead, it is returned inmeta.fields
byreturnable()
. This also means we don't need to adjustconfig.preview
to account for the header row.