fix: use function replacement in expandPrompt to prevent dollar-sign corruption (#50)#93
Open
MohammadYusif wants to merge 1 commit into
Open
fix: use function replacement in expandPrompt to prevent dollar-sign corruption (#50)#93MohammadYusif wants to merge 1 commit into
MohammadYusif wants to merge 1 commit into
Conversation
…corruption (joewalker#50) String.prototype.replaceAll interprets special patterns like $$, $&, $`, and $' in the replacement string, silently rewriting those sequences when variable values contain them. Switch to the function form `() => value` which is never pattern- interpreted, so values are always inserted verbatim. Add five regression tests in expandTemplate covering $$, $&, $`, $', and mixed dollar-sign sequences across multiple variables.
b558f37 to
7720e79
Compare
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
expandPromptsubstituted template variables using the string form ofreplaceAll, which silently interprets$$,$&,$\``, and$'` as special replacement patterns. Variable values containing these sequences — common in GitHub issue bodies (shell snippets, regex examples, monetary amounts) — were corrupted before reaching the prompt.expandIncludesalready used the correct function-form replacement; this bringsexpandPromptin line with the same pattern.Changes
src/util/expand-prompt.ts: switchreplaceAll(pattern, value)toreplaceAll(pattern, () => value)in the variable substitution loopsrc/util/__test__/expand-prompt.test.ts: add 5 regression tests covering$$,$&,$\``,$'`, and mixed sequencesFixes #50