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

Automatically escape fields that contain the comment character #283

Closed
wants to merge 3 commits into from

Conversation

dae
Copy link
Contributor

@dae dae commented Jun 8, 2022

Currently, if data is written with QuoteStyle::Necessary, and the first
field of a row happens to start with a comment character, the row will be
ignored as a comment when later reading it back in.

This change adds a comment property to Writer, and automatically
quotes fields that have the provided comment character in them, so they
round-trip correctly.

Currently, if data is written with QuoteStyle::Necessary, and the first
field of a row happens to contain a comment character, the row will be
ignored as a comment when later reading it back in.

This change adds a `comment` property to Writer, and automatically
quotes fields that have the provided comment character in them, so they
round-trip correctly.
@dae
Copy link
Contributor Author

dae commented Sep 1, 2023

@BurntSushi Gentle ping - I know you're busy. Any thoughts on if this is something you would be interested in including?

Copy link

@martinetd martinetd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense as when using the Reader interface with a comment character you'd loose lines that start with the comment if it's not escaped.

I'm not sure API-wise if it's better to have uniformity with the reader here and re-use comment, or just straight up allow setting characters to the requires_quotes array directly (as we're not writing comments!), but that's a matter of taste for @BurntSushi to decide and something that has less overhead than QuoteStyle::Always definitely looks sane to me.

It'd be great if you could spare a minute to give some feedback and/or merge this :)

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! There are a couple things that need to be addressed before merging.

csv-core/src/writer.rs Show resolved Hide resolved
src/writer.rs Show resolved Hide resolved
tests/tests.rs Outdated Show resolved Hide resolved
@dae
Copy link
Contributor Author

dae commented Oct 2, 2023

Is the latest commit what you had in mind?

csv-core/src/writer.rs Show resolved Hide resolved
src/writer.rs Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

BurntSushi pushed a commit that referenced this pull request Oct 3, 2023
Previously, if data is written with QuoteStyle::Necessary, and the
first field of a row happens to contain a comment character, the row
will be ignored as a comment when later reading it back in.

This change adds a `comment` property to Writer, and automatically
quotes fields that have the provided comment character in them, so they
round-trip correctly.

Closes #283
BurntSushi pushed a commit that referenced this pull request Oct 3, 2023
Previously, if data is written with QuoteStyle::Necessary, and the
first field of a row happens to contain a comment character, the row
will be ignored as a comment when later reading it back in.

This change adds a `comment` property to Writer, and automatically
quotes fields that have the provided comment character in them, so they
round-trip correctly.

Closes #283
@BurntSushi
Copy link
Owner

This PR is in csv 1.3.0 on crates.io.

@dae
Copy link
Contributor Author

dae commented Oct 4, 2023

Thank you very much!

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

Successfully merging this pull request may close these issues.

None yet

3 participants