Conversation
With `escape_formulas`, a leading `'` is prepended to the value after the checks deciding whether the field must be quoted were already computed. When `quote`, `escape`, `delimiter` or `record_delimiter` is set to `'`, the added character is neither escaped nor does it trigger quoting, so the output cannot be parsed back, e.g. `[["=1", "x"]]` with `quote: "'"` produced `'=1,x`. Run those checks on the prefixed value. `quoted_match` is still tested against the original value, since it expresses which user values should be quoted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
escape_formulas: true, the'prefix is added after the checks that decide whether a field has to be quoted (containsQuote,containsdelimiter,containsEscape,containsRecordDelimiter). When any ofquote,escape,delimiterorrecord_delimiteris set to', the added character is neither escaped nor does it trigger quoting, and csv-parse can no longer read the output back with the same options:This PR moves those four checks after the
escape_formulasblock, so they see the prefixed value:quoted_matchis still tested against the original value, since it expresses which user values should be quoted (e.g.quoted_match: /^=/keeps matching formula-like input). Output with the default options is unchanged.Tests: added one case each for
quote,escape,delimiterandrecord_delimiterset to'intest/option.escape_formulas.ts. All four fail without the change.npm testinpackages/csv-stringify: 236 passing; the onlytscerror, intest/option.cast.ts, is already on master since #511.