fix: config:get --shell does not double-escape backslashes in single-quoted output - #3833
Merged
Conversation
…quoted output
POSIX single-quoted strings treat all characters literally — backslashes
are NOT special and must NOT be escaped. The previous implementation ran
s.replaceAll(/(['\\])/g, String.raw\`\$1\`) on the value before wrapping
it in single quotes, so a literal backslash in a config value (e.g.
foo\nbar) was emitted as 'foo\\nbar', which the shell would interpret as
two characters, not one.
Because the single-quote branch is only reached when the string contains
no single quotes and no newlines, there are no special characters to
escape at all. The fix removes the replaceAll call entirely
(src/lib/config/quote.ts:12).
The corresponding parse() branch had a compensating
replaceAll('\\\\', '\\') to undo the double-escaping; that is also
removed since it is no longer needed and would incorrectly modify strings
that genuinely contain two consecutive backslashes
(src/lib/config/quote.ts:22).
Fixes #1384 (W-23597884)
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 19:15 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 19:15 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 19:15 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 19:15 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 21:34 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 21:34 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 21:34 — with
GitHub Actions
Inactive
heroku-johnny
temporarily deployed
to
AcceptanceTests
July 27, 2026 21:34 — with
GitHub Actions
Inactive
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.
Summary
Bug:
heroku config:get --shelldouble-escapes backslashes inside single-quoted output. A config value likefoo\nbar(one literal backslash) was emitted as'foo\\nbar', which the shell interprets as two backslashes, corrupting the value when the output iseval'd.Root cause:
src/lib/config/quote.ts:12rans.replaceAll(/(['\\])/g, String.raw\$1`)` before wrapping the string in single quotes. POSIX single-quoted strings are fully literal — backslashes have no special meaning and must not be escaped. The single-quote branch is only reached when the string contains no single quotes and no newlines, so there are nothing to escape at all.Fix: Remove the
replaceAllfrom thequote()single-quote branch (src/lib/config/quote.ts:12) and remove the compensatingreplaceAll('\\\\', '\\')from theparse()single-quote branch (src/lib/config/quote.ts:22) that was undoing the double-escaping on read-back.Test: Updated
test/unit/lib/config/quote.test.ts:11to assert the correct (un-escaped) single-quoted output. Roundtrip tests continue to pass.Fixes #1384
Fixes W-23597884
Changes
src/lib/config/quote.tsreplaceAllfrom single-quote branch inquote()src/lib/config/quote.tsreplaceAll('\\\\', '\\')from single-quote branch inparse()test/unit/lib/config/quote.test.tsTest plan
npm test -- --grep quotepasses (quote/parse unit tests including roundtrip)heroku config:set FOO='foo\nbar'theneval $(heroku config:get FOO --shell)yields a single backslash in$FOO🤖 Generated with Claude Code