Conversation
`unsafe` treats `\` as an escape character and unescapes `\\`, `\;` and `\#`, but `safe` only escaped `;` and `#`. A value or key containing a backslash therefore did not survive stringify -> parse: a value of two backslashes was written as `k=\\` and read back as a single backslash. `safe` now escapes the backslash as well. Section names are left unchanged because they rely on `\.` to escape literal dots in key paths.
|
No review on this since June, so here it is measured rather than described. I ran Round-tripping The scope is narrower than the PR title suggests, and I would rather say so. A lone backslash round-trips. The failure is silent truncation rather than an error:
With this PR's line applied to that same file: I also measured compatibility in both directions, since a change to A file written by the patched version is read correctly by the current version, for every case, so shipping this does not strand anyone's existing reader. The three mismatches in the other column are the original bug rather than something the change introduces: One deliberate exception in the diff: section names pass One thing I am not claiming: nothing reports on this branch. $ gh pr checks 307 --repo npm/ini
no checks reported on the 'fix/escape-backslash-roundtrip' branchSo the numbers above are mine, run locally against your |
ini.parse(ini.stringify(x))is not stable when a value or key contains a backslash.unsafetreats\as an escape character: in the unquoted branch it unescapes\\,\;and\#.safeonly escaped;and#, never the backslash itself, so a backslash that is written verbatim is read back as an escape sequence. Two backslashes collapse to one, and a backslash placed before;or#gets swallowed.This makes
safeescape the backslash as well, so it is the inverse ofunsafe. Section names are left unchanged: they use\.to escape literal dots in key paths, sosafeis called withescapeBackslash = falsefor the section to avoid doubling those structural backslashes. The existing snapshots are byte-identical.Round-trip tests are added in
test/bar.js(two backslashes, a Windows-style path,\;/\#, and a backslash in a key).npm testpasses at 100% coverage, and reverting the one-line change makes the new cases fail.This is the behaviour #9 had in mind: "a
\\needs to be a\and not an escape".