Skip to content

fix(core): substitute $FILE and ${path} literally in formatter and prompt templates - #54918

Closed
franitel wants to merge 2 commits into
anomalyco:devfrom
franitel:literal-path-substitution
Closed

franitel wants to merge 2 commits into
anomalyco:devfrom
franitel:literal-path-substitution

Conversation

@franitel

Copy link
Copy Markdown

Issue for this PR

Fixes #52314

Type of change

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

What does this PR do?

String.prototype.replace expands $-sequences in the replacement string, so a file or directory whose name contains $& (or $', $`, $$) was corrupted when substituted into the formatter argv ($FILE) and the /init and /review prompt templates (${path}). The formatter then ran on a nonexistent path and silently skipped the file.

Switched those sites to function replacers, which insert the value verbatim (the same pattern already used elsewhere in the codebase):

  • packages/core/src/formatter.ts — $FILE substitution
  • packages/core/src/plugin/command.ts — ${path} in the init and review templates

How did you verify your code works?

Extended packages/core/test/formatter.test.ts with a case that formats a file named test$&.md and asserts its content is written; updated packages/core/test/plugin/command.test.ts to run the init/review commands with a project directory containing $& and assert the prompt text contains the literal path.

Ran in packages/core:

  • bun test test/formatter.test.ts test/plugin/command.test.ts → 28 pass, 0 fail
  • bun typecheck → clean

Screenshots / recordings

N/A (no UI change)

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I ran the two updated test files against the base and both new cases failed: the file test$&.md was never formatted, and the /init and /review prompts got a mangled project path. With this PR both test files pass (28/28), and bun run typecheck in packages/core is clean. These were the only places in the repo where a file or directory path is filled into a template with a plain-string replace.

Public API is unchanged.

No blocking concerns.

@franitel
franitel force-pushed the literal-path-substitution branch from 4d5202b to 9718801 Compare October 14, 2026 11:39
@franitel

franitel commented Oct 14, 2026 •

Copy link
Copy Markdown
Author

The CI workflow runs on this fork PR are still waiting for approval — could a maintainer approve them?

I also extended the regression tests to cover $', $` and $$ in addition to $&, and verified every case fails without the fix.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter argv and prompt templates corrupt paths containing $-sequences ($&, $', $`, $$)

1 participant