fix(filesystem): preserve literal dollar replacements (#4225)

Co-authored-by: Ola Hungerford <olahungerford@gmail.com>
This commit is contained in:
Krish Garg 2026-05-29 21:27:03 -07:00 • committed by GitHub
commit 00ce9cf134
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -440,6 +440,22 @@ describe('Lib Functions', () => {
);
});
it('treats dollar signs in replacement text literally', async () => {
const edits = [
{ oldText: 'line2', newText: "price=$$; match=$&; before=$`; after=$'" }
];
mockFs.rename.mockResolvedValueOnce(undefined);
await applyFileEdits('/test/file.txt', edits, false);
expect(mockFs.writeFile).toHaveBeenCalledWith(
expect.stringMatching(/\/test\/file\.txt\.[a-f0-9]+\.tmp$/),
"line1\nprice=$$; match=$&; before=$`; after=$'\nline3\n",
'utf-8'
);
});
it('handles dry run mode', async () => {
const edits = [
{ oldText: 'line2', newText: 'modified line2' }

View file

@ -207,7 +207,7 @@ export async function applyFileEdits(
// If exact match exists, use it
if (modifiedContent.includes(normalizedOld)) {
modifiedContent = modifiedContent.replace(normalizedOld, normalizedNew);
modifiedContent = modifiedContent.replace(normalizedOld, () => normalizedNew);
continue;
}