Skip to content

fix(core): insert template values verbatim to prevent $-sequence corr… - #55320

Closed
gorredinesh21 wants to merge 1 commit into
anomalyco:devfrom
gorredinesh21:fix/template-fill-dollar-sequence-v2
Closed

gorredinesh21 wants to merge 1 commit into
anomalyco:devfrom
gorredinesh21:fix/template-fill-dollar-sequence-v2

Conversation

@gorredinesh21

Copy link
Copy Markdown

…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.

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

…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.
@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No "Type of change" checkbox is checked. Please select at least one.
  • No issue referenced. Please add Closes #<number> linking to the relevant issue.
  • "How did you verify your code works?" section is empty. Please explain how you tested.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot closed this Oct 14, 2026
@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks for following up on this fix!

This still looks like a duplicate of #54918, which is open and fixes #52314 at the same three places: $FILE in formatter.ts, and the ${path} fills for /init and /review in plugin/command.ts. It uses function replacers there too, and has tests with real $& paths. The only difference here is the literalReplace helper. Your earlier #55317 and #55319 were closed for the same reason, so opening it again won't change the outcome.

If you think #54918 should use a shared helper or test more cases ($', $`, $$), a review or comment on #54918 would be the most helpful way to get that in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant