Repository navigation
Copilot: write $ patterns in memory str_replace as they are - #350865
Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
Conversation
The memory tool's str_replace passed new_str to String.replace as a string, so $', $`, $& and $$ in it were expanded. A note containing $' or $` copied the rest or the start of the file into it. Pass a function instead. Fixes #323167 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues require resolution, though tests were not independently run.
No open issues 🎉
What changed in this PR
Prevents Copilot memory-file corruption when str_replace replacement text contains special dollar patterns, addressing #323167.
Changes:
- Uses a replacement callback so
new_stris written literally rather than interpreted byString.prototype.replace. - Adds a regression test covering dollar patterns and preservation of surrounding file content.
No actionable findings remain. Tests were not independently run.
| File | Description |
|---|---|
extensions/copilot/src/extension/tools/node/test/memoryTool.spec.tsx |
Adds regression coverage for literal dollar-pattern replacements. |
extensions/copilot/src/extension/tools/node/memoryTool.tsx |
Writes replacement text without expanding special dollar patterns. |
Review effort: Balanced
This branch has not been deployed
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.
Fixes #323167
The memory tool's
str_replacepassednew_strtoString.prototype.replaceas a string, so$',$`,$&and$$in it were expanded instead of written. A memory note containing$'or$`(shell quoting, regular expressions, prices like`32$`) copied the rest or the start of the file into itself, and$$became$. The comments in #323167 trace a corrupted memory file back to this.This PR passes a function as the replacement, so
new_stris written as it is.insertbuilds the file withspliceand wasn't affected.How to test
cd extensions/copilot && npx vitest --run --pool=forks src/extension/tools/node/test/memoryTool.spec.tsx