fix(proofread): support text replacement for text with no word boundaries, closes #2889 (#2894)

This commit is contained in:
Huang Xin
2026-01-09 10:27:38 +01:00
committed by GitHub
parent cfe51d01ee
commit 5eecc735aa
2 changed files with 84 additions and 3 deletions
@@ -209,6 +209,60 @@ describe('proofreadTransformer', () => {
expect(result).toContain('dog');
expect(result).toContain('category'); // Should not replace "cat" in "category"
});
test('should replace CJK characters correctly', async () => {
const rules: ProofreadRule[] = [
{
id: '1',
scope: 'book',
pattern: '猫',
replacement: '狗',
enabled: true,
isRegex: false,
caseSensitive: true,
order: 1,
wholeWord: true,
},
];
const ctx = createMockContext(rules, '<p>我有一只猫。</p>');
const result = await proofreadTransformer.transform(ctx);
expect(result).toContain('我有一只狗。');
expect(result).not.toContain('猫');
});
test('should replace multiple different words correctly', async () => {
const rules: ProofreadRule[] = [
{
id: '1',
scope: 'book',
pattern: '猫',
replacement: '狗',
enabled: true,
isRegex: false,
caseSensitive: true,
order: 1,
wholeWord: true,
},
{
id: '2',
scope: 'book',
pattern: '我',
replacement: '你',
enabled: true,
isRegex: false,
caseSensitive: true,
order: 2,
wholeWord: true,
},
];
const ctx = createMockContext(rules, '<p>我有一只猫。</p>');
const result = await proofreadTransformer.transform(ctx);
expect(result).toContain('你有一只狗。');
expect(result).not.toContain('我');
expect(result).not.toContain('猫');
});
});
describe('regex functionality', () => {