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

CsvReader fails to parse file with some quoted fields #67

Closed
oflege opened this issue Nov 8, 2022 · 3 comments
Closed

CsvReader fails to parse file with some quoted fields #67

oflege opened this issue Nov 8, 2022 · 3 comments
Assignees
Labels

Comments

@oflege
Copy link

oflege commented Nov 8, 2022

Describe the bug
CsvReader with errorOnDifferentFieldCount(true) fails for a particular csv file. If I change anything in that file before the problematic line 228 (delete a row, add/remove a char from a field in a row) or replace the double quotes in line 228 with single quotes, the CsvReader does not fail.

To Reproduce
JUnit test to reproduce the behavior:

        try (CsvReader r = CsvReader.builder().fieldSeparator(';').errorOnDifferentFieldCount(true)
                .build(new File("a.csv").toPath(), StandardCharsets.ISO_8859_1)
        ) {
            r.iterator().forEachRemaining(System.out::println);
        }

a.csv

@osiegmar osiegmar self-assigned this Nov 8, 2022
@osiegmar osiegmar added the bug label Nov 8, 2022
@osiegmar
Copy link
Owner

osiegmar commented Nov 8, 2022

Thanks for reporting this issue! Given your test code and data I could successfully reproduce and fix it.

The problem was caused by the combination of two things:

  • Quote character within an unquoted field (nonconforming data per section 2.5 of RFC 4180)
  • Need to refill the input buffer while parsing such a field

Could you give the develop branch a try if it fixes your problem with real data?

@oflege
Copy link
Author

oflege commented Nov 9, 2022

Thanks a lot for the quick fix, I just tested the code in the develop branch with our curent set of csv files and all were parsed successfully

@osiegmar
Copy link
Owner

osiegmar commented Nov 9, 2022

Thanks! Fixed in 2.2.1 just released.

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

No branches or pull requests

2 participants