Skip to content

Failure to parse content when last line is a comment. #363

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

Open
Comattin opened this issue Apr 24, 2024 · 1 comment · May be fixed by #396
Open

Failure to parse content when last line is a comment. #363

Comattin opened this issue Apr 24, 2024 · 1 comment · May be fixed by #396
Labels

Comments

@Comattin
Copy link

What version of the csv crate are you using?

csv 1.3.0

Briefly describe the question, bug or feature request.

When the last line of the csv data is a comment, deserialization results in a CSV error stating that the found record does not have the appropriate number of fields when the expectation is that the line should be ignored all together since it starts with the comment character. Example error message: CSV error: record 2 (line: 5, byte: 70): found record with 1 fields, but the previous record has 3 fields

Include a complete program demonstrating a problem.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=62901b8c4ce6c97e87a2dc73cfcc267a

What is the observed behavior of the code above?

Standard Output
Beginning test case: Content ends with a record.
Test case finished.
Beginning test case: Content ends with a newline.
Test case finished.
Beginning test case: Content ends with an #Comment then newline.
Test case finished.
Beginning test case: Content ends with an #Comment.
CSV error: record 2 (line: 5, byte: 70): found record with 1 fields, but the previous record has 3 fields

What is the expected or desired behavior of the code above?

Standard output should be:
Beginning test case: Content ends with a record.
Test case finished.
Beginning test case: Content ends with a newline.
Test case finished.
Beginning test case: Content ends with an #Comment then newline.
Test case finished.
Beginning test case: Content ends with an #Comment.
Test case finished.

@BurntSushi BurntSushi added the bug label Apr 24, 2024
@BurntSushi
Copy link
Owner

Nice find.

DCjanus added a commit to DCjanus/rust-csv that referenced this issue Apr 27, 2025
This test reproduces issue BurntSushi#363, ensuring that comments at the end of the input data are properly ignored by the CSV reader.
DCjanus added a commit to DCjanus/rust-csv that referenced this issue Apr 27, 2025
Refines the test for ignoring comments at the end of the input data by removing the second record assertion, ensuring that only relevant records are processed. This addresses the behavior outlined in issue BurntSushi#363.
DCjanus added a commit to DCjanus/rust-csv that referenced this issue Apr 27, 2025
DCjanus added a commit to DCjanus/rust-csv that referenced this issue Apr 27, 2025
Refines the logic to ensure comments at the end of the file are ignored, addressing issue BurntSushi#363. Additionally, updates the test to validate this behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants