Skip to content
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

strict: false - headers lost after row with wrong number of columns #150

Open
aheissenberger opened this issue Oct 10, 2019 · 4 comments
Open

Comments

@aheissenberger
Copy link
Contributor

  • Operating System: MacOS 10.14.6
  • Node Version: v12.11.1
  • NPM Version: 6.11.3
  • csv-parser Version: 2.3.1

Expected Behavior

headers created with "mapHeaders" should be used for all valid records, even for records with to many or to less columns

Actual Behavior

  • when a line contains more columns than headers the broken record is returned with indexed keys.
  • any valid line following the broken line is returned with indexed key and not with the headers

How Do We Reproduce?

https://github.com/aheissenberger/csv-parser?organization=aheissenberger&organization=aheissenberger

1 test failed

  strictNo › strictNo

  /Users/ah/SVN-Checkouts/DEV/csv-parser/test/strictNo.test.js:9

   8:     const headersLastLine = Object.keys(lines[2]) 
   9:     t.deepEqual(headersFirstLine, headersLastLine)
   10:     t.false(err, 'no err')                        

  Difference:

    [
  -   'a',
  +   '0',
  -   'b',
  +   '1',
  -   'c',
  +   '2',
    ]
@armontero
Copy link

Any updates on the fix for this issue? I'm stuck trying to parse a large file and I encounter this error about 2/3 of the way through. All the data after this error only includes the indexed keys.

Is there a workaround in the meantime? Thanks!

@armontero
Copy link

It appears that when this happens and the headers are replaced by column indexes, the 'end' event is never generated. I wrote a function to re-apply the headers once this problem is encountered, but now my code hangs when the end of the file is reached. It never enters the code block for the .on('end') event.

@ewrayjohnson
Copy link

I am seeing this too

@58bcbedf47bd91439c
Copy link

Has this bug been fixed in the version of CSV parser: 2.3.3
When using the version of CSV parser: 2.3.3, this problem still occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants