Skip to content

Commit

Permalink
More rigorously check surrogate pairs in regexp validator
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Mar 9, 2020
1 parent df0cf1a commit 90a9548
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions acorn/src/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class RegExpValidationState {
if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
return c
}
return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00
const next = s.charCodeAt(i + 1)
return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
}

nextIndex(i) {
Expand All @@ -59,8 +60,9 @@ export class RegExpValidationState {
if (i >= l) {
return l
}
const c = s.charCodeAt(i)
if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
let c = s.charCodeAt(i), next
if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
(next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
return i + 1
}
return i + 2
Expand Down
1 change: 1 addition & 0 deletions test/tests-regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ test("/[\\d][\\12-\\14]{1,}[^\\d]/", {}, { ecmaVersion: 2015 })
testFail("/[\\d][\\12-\\14]{1,}[^\\d]/u", "Invalid regular expression flag (1:1)", { ecmaVersion: 5 })
testFail("/[\\d][\\12-\\14]{1,}[^\\d]/u", "Invalid regular expression: /[\\d][\\12-\\14]{1,}[^\\d]/: Invalid class escape (1:1)", { ecmaVersion: 2015 })
test("/([a ]\\b)*\\b/", {}, { ecmaVersion: 5 })
test("/[x-*]/u".replace("*", String.fromCharCode(0xd800)), {}, {ecmaVersion: 6})

/*
// This is test case generator.
Expand Down

0 comments on commit 90a9548

Please sign in to comment.