Repository navigation
fix(core): insert template values verbatim to prevent $-sequence corr… - #55319
Closed
gorredinesh21 wants to merge 1 commit into
Closed
gorredinesh21 wants to merge 1 commit into
gorredinesh21 wants to merge 1 commit into
Conversation
…uption String.prototype.replace interprets $-sequences ($&, $', $`, $$) in string replacements. Filling templates with user-controlled values (file paths, project directories) via a string replacer silently corrupts the result: - formatter argv: a path like /tmp/a$&b.ts becomes /tmp/a$FILEb.ts, so the formatter is invoked on a nonexistent file - /init and /review command templates: a project path containing $' mangles the assembled prompt Add literalReplace() (function-replacer form, matching the existing $ARGUMENTS fill in plugin/command.ts) and migrate the affected call sites. First-match semantics are preserved.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
Contributor
|
Thanks for porting your fix from #52315 to v2, and for the clear write-up and the mutation-checked tests! I think this duplicates #54918, which is still open and fixes #52314 at the same three places: If you think #54918 is missing something, such as coverage for |
This was referenced Oct 14, 2026
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.
Issue for this PR
Closes #52314
Type of change
What does this PR do?
String.prototype.replaceexpands$-sequences ($&,$',$`,$$) in the replacement string, so template fills with user-controlled values corrupt their input: a file path like/tmp/a$&b.tsfilled into the formatter argv becomes/tmp/a$FILEb.ts, and a project path containing$'mangles the/initand/reviewprompt templates.This ports the fix from #52315 to V2, as requested when that PR was closed: add a
literalReplace()helper using a function replacer (the same approach the$ARGUMENTSfill inplugin/command.tsalready uses) and use it at the three affected sites — the$FILEfill informatter.tsand the${path}fills inplugin/command.ts. First-match semantics are unchanged.How did you verify your code works?
New
test/template.test.tscovers plain fills and each$-sequence case. Mutation check: reverting the helper to a plain string replacer makes the suite fail; with the fix it passes. Existingformatter.test.tsandcommand.test.tspass unchanged, andbun run typecheck+ oxlint are clean inpackages/core.Screenshots / recordings
Not a UI change.
Checklist