Skip to content

Commit 88bea3f

Browse files
committed
Fix newline normalization in search for \n\n
Fix microsoft#86935
1 parent ba72bf8 commit 88bea3f

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export type IRgBytesOrText = { bytes: string } | { text: string };
533533
export function fixRegexNewline(pattern: string): string {
534534
// Replace an unescaped $ at the end of the pattern with \r?$
535535
// Match $ preceeded by none or even number of literal \
536-
return pattern.replace(/([^\\]|^)(\\\\)*\\n/g, '$1$2\\r?\\n');
536+
return pattern.replace(/(?<=[^\\]|^)(\\\\)*\\n/g, '$1\\r?\\n');
537537
}
538538

539539
export function fixNewline(pattern: string): string {

src/vs/workbench/services/search/test/node/ripgrepTextSearchEngine.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite('RipgrepTextSearchEngine', () => {
2727
assert.equal(unicodeEscapesToPCRE2(''), '');
2828
});
2929

30-
test('fixRegexNewline', () => {
30+
test.only('fixRegexNewline', () => {
3131
function testFixRegexNewline([inputReg, testStr, shouldMatch]: [string, string, boolean]): void {
3232
const fixed = fixRegexNewline(inputReg);
3333
const reg = new RegExp(fixed);
@@ -38,6 +38,8 @@ suite('RipgrepTextSearchEngine', () => {
3838
['foo', 'foo', true],
3939

4040
['foo\\n', 'foo\r\n', true],
41+
['foo\\n\\n', 'foo\n\n', true],
42+
['foo\\n\\n', 'foo\r\n\r\n', true],
4143
['foo\\n', 'foo\n', true],
4244
['foo\\nabc', 'foo\r\nabc', true],
4345
['foo\\nabc', 'foo\nabc', true],

0 commit comments

Comments
 (0)