Skip to content

Commit 6039af8

Browse files
adamfweidmanAdib234
authored andcommitted
refactor(core): robust trimPreservingTrailingNewline and regression test (#18196)
1 parent 430b80d commit 6039af8

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

packages/core/src/utils/editCorrector.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,30 @@ describe('editCorrector', () => {
665665
expect(result.params.new_string).toBe('replaced\n\n');
666666
expect(result.occurrences).toBe(1);
667667
});
668+
669+
it('Test 7.2: should handle trailing newlines separated by spaces (regression fix)', async () => {
670+
const currentContent = 'find me '; // Matches old_string initially
671+
const originalParams = {
672+
file_path: '/test/file.txt',
673+
old_string: 'find me ', // Trailing space
674+
new_string: 'replaced \n \n', // Trailing newlines with spaces
675+
};
676+
677+
const result = await ensureCorrectEdit(
678+
'/test/file.txt',
679+
currentContent,
680+
originalParams,
681+
mockGeminiClientInstance,
682+
mockBaseLlmClientInstance,
683+
abortSignal,
684+
false,
685+
);
686+
687+
expect(result.params.old_string).toBe('find me');
688+
// Should capture both newlines and join them, stripping the space between
689+
expect(result.params.new_string).toBe('replaced\n\n');
690+
expect(result.occurrences).toBe(1);
691+
});
668692
});
669693
});
670694

0 commit comments

Comments
 (0)