Fix dollar sign replacement bug in file editing (#7703)

This commit is contained in:
fuyou
2025-09-05 10:12:57 +08:00
committed by GitHub
parent aea6230bcc
commit 0bc0d23cb3
6 changed files with 68 additions and 23 deletions
+17 -1
View File
@@ -46,11 +46,11 @@ import {
type Mock,
} from 'vitest';
import {
applyReplacement,
SmartEditTool,
type EditToolParams,
calculateReplacement,
} from './smart-edit.js';
import { applyReplacement } from './edit.js';
import { type FileDiff, ToolConfirmationOutcome } from './tools.js';
import { ToolErrorType } from './tool-error.js';
import path from 'node:path';
@@ -169,6 +169,22 @@ describe('SmartEditTool', () => {
'hello new world new',
);
});
it('should treat $ literally and not as replacement pattern', () => {
const current = 'regex end is $ and more';
const oldStr = 'regex end is $';
const newStr = 'regex end is $ and correct';
const result = applyReplacement(current, oldStr, newStr, false);
expect(result).toBe('regex end is $ and correct and more');
});
it("should treat $' literally and not as a replacement pattern", () => {
const current = 'foo';
const oldStr = 'foo';
const newStr = "bar$'baz";
const result = applyReplacement(current, oldStr, newStr, false);
expect(result).toBe("bar$'baz");
});
});
describe('calculateReplacement', () => {