Repository navigation
fix(csv-stringify): skip escaping empty quote strings - #563
MirandaCavalie wants to merge 3 commits into
Conversation
|
Hi @MirandaCavalie could you reduce the number of tests to the minimum. Thank you |
Thanks, David! Reduced this to a single regression test and confirmed it fails without the fix and passes with it. The full suite also passes locally |
| } | ||
| // Escape all quote characters if quoted | ||
| if (shouldQuote === true) { | ||
| if (shouldQuote === true && containsQuote === true) { |
There was a problem hiding this comment.
containsQuote is computed before the escape_formulas block, which can add a ' in front of the value. When the quote char is ', that new quote is no longer escaped, so the output can't be parsed back:
const opts = { quote: "'", escape: "'", quoted: true, escape_formulas: true };
stringify([["=1", "b"]], opts);
// master: "'''=1','b'\n" → parse gives [["'=1","b"]]
// this PR: "''=1','b'\n" → parse throws "Invalid Closing Quote: got \"=\""Same with quoted_match instead of quoted. Checking the empty quote directly fixes the quote: false case without depending on the earlier flag:
| if (shouldQuote === true && containsQuote === true) { | |
| if (shouldQuote === true && quote !== "") { |
There was a problem hiding this comment.
Thanks for catching this! Applied your suggestion and added a regression test that fails before the fix and passes afterward. The full suite passes locally
There was a problem hiding this comment.
Checked a45082b: =1 with quote: "'" now round-trips through csv-parse for both quoted and quoted_match, and quote: false / quote: "" with quoted: true give abc,d with no stray quotes. The 160 stringify tests pass for me. Thanks.
Fix the regression introduced by #559: disabled quoting inserts escape characters between every character when a quoting selector is active.
Skip quote escaping when
quoteis empty. Checking the quote directly also preserves escaping of the apostrophe added byescape_formulaswhen using a custom quote, as identified in review.Two minimal regression tests cover disabled quoting and formula escaping with an apostrophe quote. The formula test fails on the previous PR implementation and passes with this change; the original disabled-quote test remains passing.
Validation:
npm run buildpasses for all 7 projects;npm testpasses for all 14 projects (1,119 passing, 5 existing pending).npm test --workspace=csv-stringifypasses on each (245 passing, 1 existing pending).git diff --checkpass.Full build and tests ran on macOS in a checkout without spaces, with the three PR files verified identical to the submitted files.