Skip to content

Commit fbc15b1

Browse files
committed
More rigorously check surrogate pairs in regexp validator
1 parent 910e62b commit fbc15b1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/regexp.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export class RegExpValidationState {
4848
if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
4949
return c
5050
}
51-
return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
51+
const next = s.charCodeAt(i + 1)
52+
return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
5253
}
5354

5455
nextIndex(i) {
@@ -57,8 +58,9 @@ export class RegExpValidationState {
5758
if (i >= l) {
5859
return l
5960
}
60-
const c = s.charCodeAt(i)
61-
if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
61+
let c = s.charCodeAt(i), next
62+
if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
63+
(next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
6264
return i + 1
6365
}
6466
return i + 2

test/tests-regexp.js

+1
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ test("/[\\d][\\12-\\14]{1,}[^\\d]/", {}, { ecmaVersion: 2015 })
10491049
testFail("/[\\d][\\12-\\14]{1,}[^\\d]/u", "Invalid regular expression flag (1:1)", { ecmaVersion: 5 })
10501050
testFail("/[\\d][\\12-\\14]{1,}[^\\d]/u", "Invalid regular expression: /[\\d][\\12-\\14]{1,}[^\\d]/: Invalid class escape (1:1)", { ecmaVersion: 2015 })
10511051
test("/([a ]\\b)*\\b/", {}, { ecmaVersion: 5 })
1052+
test("/[x-*]/u".replace("*", String.fromCharCode(0xd800)), {}, {ecmaVersion: 6})
10521053

10531054
/*
10541055
// This is test case generator.

0 commit comments

Comments
 (0)