Skip to content

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

@Comattin

Description

@Comattin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions