Step over surrogate pairs on zero-lenth matches (fixes #100134)
This commit is contained in:
parent
6eb2604096
commit
206c06b530
2 changed files with 31 additions and 2 deletions
|
@ -548,8 +548,12 @@ export class Searcher {
|
|||
if (matchStartIndex === this._prevMatchStartIndex && matchLength === this._prevMatchLength) {
|
||||
if (matchLength === 0) {
|
||||
// the search result is an empty string and won't advance `regex.lastIndex`, so `regex.exec` will stuck here
|
||||
// we attempt to recover from that by advancing by one
|
||||
this._searchRegex.lastIndex += 1;
|
||||
// we attempt to recover from that by advancing by two if surrogate pair found and by one otherwise
|
||||
if (strings.getNextCodePoint(text, textLength, this._searchRegex.lastIndex) > 0xFFFF) {
|
||||
this._searchRegex.lastIndex += 2;
|
||||
} else {
|
||||
this._searchRegex.lastIndex += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Exit early if the regex matches the same range twice
|
||||
|
|
|
@ -781,4 +781,29 @@ suite('TextModelSearch', () => {
|
|||
|
||||
model.dispose();
|
||||
});
|
||||
|
||||
test('issue #100134. Zero-length matches should properly step over surrogate pairs', () => {
|
||||
// 1[Laptop]1 - there shoud be no matches inside of [Laptop] emoji
|
||||
assertFindMatches('1\uD83D\uDCBB1', '()', true, false, null,
|
||||
[
|
||||
[1, 1, 1, 1],
|
||||
[1, 2, 1, 2],
|
||||
[1, 4, 1, 4],
|
||||
[1, 5, 1, 5],
|
||||
|
||||
]
|
||||
);
|
||||
// 1[Hacker Cat]1 = 1[Cat Face][ZWJ][Laptop]1 - there shoud be matches between emoji and ZWJ
|
||||
// there shoud be no matches inside of [Cat Face] and [Laptop] emoji
|
||||
assertFindMatches('1\uD83D\uDC31\u200D\uD83D\uDCBB1', '()', true, false, null,
|
||||
[
|
||||
[1, 1, 1, 1],
|
||||
[1, 2, 1, 2],
|
||||
[1, 4, 1, 4],
|
||||
[1, 5, 1, 5],
|
||||
[1, 7, 1, 7],
|
||||
[1, 8, 1, 8]
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue