Skip to content

fix: use function replacement in expandPrompt to prevent dollar-sign corruption (#50)#93

Open
MohammadYusif wants to merge 1 commit into
joewalker:mainfrom
MohammadYusif:fix/issue-50
Open

fix: use function replacement in expandPrompt to prevent dollar-sign corruption (#50)#93
MohammadYusif wants to merge 1 commit into
joewalker:mainfrom
MohammadYusif:fix/issue-50

Conversation

@MohammadYusif
Copy link
Copy Markdown

Summary

expandPrompt substituted template variables using the string form of replaceAll, 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.

expandIncludes already used the correct function-form replacement; this brings expandPrompt in line with the same pattern.

Changes

  • src/util/expand-prompt.ts: switch replaceAll(pattern, value) to replaceAll(pattern, () => value) in the variable substitution loop
  • src/util/__test__/expand-prompt.test.ts: add 5 regression tests covering $$, $&, $\``, $'`, and mixed sequences

Fixes #50

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expandPrompt: dollar-sign sequences in variable values are silently corrupted by String.prototype.replaceAll

1 participant