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

Incorrect parsing of wrapped values #214

Closed
4 of 5 tasks
pavelhoral opened this issue Jan 6, 2022 · 5 comments
Closed
4 of 5 tasks

Incorrect parsing of wrapped values #214

pavelhoral opened this issue Jan 6, 2022 · 5 comments
Labels
bug csv2json CSV to JSON

Comments

@pavelhoral
Copy link

pavelhoral commented Jan 6, 2022

Background Information

  • Module Version: master
  • Node/Browser Version: irrelevant

The issue I'm reporting is with:

  • json2csv
  • csv2json

I have...

  • searched to see if an issue has already been reported.
  • verified that my JSON/CSV data is valid (using something like http://jsonlint.com or https://csvlint.io/).
  • tried upgrading to the latest version of json-2-csv (since the issue may already be fixed).

Expected Behavior

Quoted values split across multiple lines should be correctly parsed.

Actual Behavior

The parser behaves incorrectly when the end quote is at the start of a new line.

Data Sample

CSV:

first,second
"hello
",world

This is being parsed as:

[
  {
    "first": "\",world\n"
  }
]

I did try to fix it but the parser makes almost no sense to me so I am creating this issue and going to find another library or write my own parser :). Good luck.

@mrodrig
Copy link
Owner

mrodrig commented Jan 7, 2022

Thanks for reporting this @pavelhoral and apologies that it wasn't working as anticipated for your use case. I've confirmed I can reproduce this issue. I suspect it's a bug with the CSV string parser logic where something isn't quite getting stored properly. I should have some time to walk through this closer this coming weekend, so I'll keep you posted as to when I have a fix published on NPM.

@mrodrig mrodrig added bug csv2json CSV to JSON labels Jan 7, 2022
mrodrig added a commit that referenced this issue Jan 9, 2022
mrodrig added a commit that referenced this issue Jan 9, 2022
As reported in #214, there was a bug with how the CSV parser was handling quoted fields which had newlines (or EOL delimiters) embedded in them. Since the value is wrapped in quotes, the EOL delimiter should not be interpreted as though it's a new line or the start of another field as it previously was. This commit introduces a fix to ensure that quoted fields are parsed properly regardless of whether there is a nested EOL delimiter inside.

Fixes #214
@mrodrig mrodrig closed this as completed in a608a38 Jan 9, 2022
@mrodrig
Copy link
Owner

mrodrig commented Jan 9, 2022

Thanks again for reporting this @pavelhoral. I'll be pushing version 3.15.1 to NPM shortly which fixes the issue you identified.

@symbianm
Copy link

symbianm commented Oct 3, 2023

This bug still exists in the latest 4.1.0 version. From this test file I am getting two incomplete rows
test.csv

@symbianm
Copy link

symbianm commented Oct 8, 2023

I have created new issue #240 because of no answer

@mrodrig
Copy link
Owner

mrodrig commented Oct 29, 2023

Hi @symbianm. The bug reported in this issue is not still present in 4.1.0. As tested with the latest release, the output for the CSV sample provided with this issue returns the following, which is correct:

[
    {
        "first": "hello\n",
        "second": "world"
    }
]

I will now switch over to #240 to look into the separate issue you're reporting.

Repository owner locked as resolved and limited conversation to collaborators Oct 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug csv2json CSV to JSON
Projects
None yet
Development

No branches or pull requests

3 participants