提交 206c06b5 编写于 作者: I IllusionMH

Step over surrogate pairs on zero-lenth matches (fixes #100134)

上级 6eb26040
......@@ -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]
]
);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册