fix(filesystem): preserve literal dollar replacements (#4225)
Co-authored-by: Ola Hungerford <olahungerford@gmail.com>
This commit is contained in:
parent
ce3b44e21b
commit
00ce9cf134
2 changed files with 17 additions and 1 deletions
|
|
@ -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' }
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue