Skip to content

fix(writer): escape the escape character when double_quote is false - #444

Open
Yshuro wants to merge 1 commit into
BurntSushi:masterfrom
Yshuro:fix/issue-443
Open

Yshuro wants to merge 1 commit into
BurntSushi:masterfrom
Yshuro:fix/issue-443

Conversation

@Yshuro

@Yshuro Yshuro commented Nov 21, 2026

Copy link
Copy Markdown

Fixes #443

Problem

When double_quote is set to false and an escape byte is configured (e.g. b'\\'), quotes inside fields are escaped (\"), but occurrences of the escape character itself were previously written unescaped.
When reading the output back with the matching escape byte, the reader discards the unescaped backslash, causing round-trip data loss (e.g. "a\b" is read back as ab).

Solution

  • In csv_core::quote, when double_quote is false, search for both quote and escape bytes using memchr2.
  • When encountering an escape byte in the field, escape it by prepending escape ([escape, escape]).
  • Added tests in csv-core and csv::writer confirming round-trip serialization and deserialization.

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.

Writer does not escape the escape character when double_quote(false)

1 participant