fix(env): unquote reverses backslash escape#4
Open
oratis wants to merge 1 commit into
Open
Conversation
quoteValue / unquote in src/env.ts were asymmetric: writing a value containing `\` escaped it to `\\` in config.env, but reading it back never unescaped, so every save/load cycle doubled the backslashes. Windows paths and any tokens with literal backslashes accumulated extra characters indefinitely. Single-pass replace with a substitution callback so `\\`, `\"`, and `\n` are all undone in one go (avoids the ordering trap where a naive `/\\\\/ → \\` first-pass would collide with `\\n`). Verified by 10-case round-trip table including ASCII-safe (passthrough), spaces, quotes, newlines, single + double + trailing backslashes, Windows paths, and a combo of all three escape sequences. Closes #3 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #3.
What
quoteValueandunquoteinsrc/env.tswere asymmetric.saveConfigEnvescapes\→\\when serializing, butloadConfigEnv→unquoteonly reverses\"→"and\n→ newline — it never undoes the\\. Every save/load cycle therefore doubled the number of backslashes in any value containing one.Before vs after (round-trip)
unquotereturnedC:\Users\path"C:\\Users\\path"C:\\Users\\path✗C:\Users\path✓API\KEY_X"API\\KEY_X"API\\KEY_X✗API\KEY_X✓with\backslash"with\\backslash"with\\backslash✗with\backslash✓ASCII-safe values (no special chars), values with
", and values with\nwere unaffected — still round-trip identically.Change
Single-pass replace with a substitution callback. The alternative — three sequential
.replace()calls — has an ordering trap: doing/\\\\/g → \\first would consume the leading\\in\\nand produce a stray\ntoken; doing\nfirst would produce a real newline before the\\step could see the surrounding context. The callback form covers all three escape sequences in one left-to-right pass.Verification
10-case round-trip test (passthrough, spaces, quotes, newlines, single/double/trailing backslashes, Windows paths, combination): all pass. Output in the issue body.
Scope
src/env.ts), one function (unquote, 3-line change)npm run typecheckclean🤖 Generated with Claude Code