Skip to content

Commit ecaae5b

Browse files
committed
[MERGE #5027 @rhuanjl] RegExp syntax error for invalid Unicode codepoint fix #2753
Merge pull request #5027 from rhuanjl:RegExpInvaludUnicode Somewhat self-explanatory fix for #2753 Note three of the currently tested RegExps in the unicode_escape_sequences.js test become invalid with this change - I verified that they were already invalid with other engines using eshost then updated them. I also added an extra case to that file to explicitly test for this.
2 parents d720588 + a41850f commit ecaae5b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/Parser/RegexParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ namespace UnifiedRegex
257257

258258
if (codePoint > 0x10FFFF)
259259
{
260+
DeferredFailIfUnicode(JSERR_RegExpInvalidEscape);
260261
return 0;
261262
}
262263
i++;

test/es6/unicode_escape_sequences.baseline

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
SyntaxError: Syntax error in regular expression
22
SyntaxError: Invalid codepoint value in the escape sequence.
33
SyntaxError: Invalid range in character set
4+
SyntaxError: Invalid regular expression: invalid escape in unicode pattern
45
false
56
false
67
false

test/es6/unicode_escape_sequences.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ try {
8181
e.echo();
8282
}
8383

84+
try {
85+
new RegExp(/\u{10FFFF}/,"u");
86+
}
87+
catch (e)
88+
{
89+
print ("Unexpected error " + e);
90+
}
91+
92+
try {
93+
new RegExp(/\u{110000}/, "u");
94+
}
95+
catch (e)
96+
{
97+
print (e);
98+
}
99+
84100
// Shouldn't throw From here onwards.
85101
eval('var test = "\\u{0000}"');
86102

@@ -169,11 +185,11 @@ invalidStrings.forEach(function (str){
169185
/a\u{}b/u.test("au\{\}b").echo();
170186
/a\u{1}b/u.test("a\u0001b").echo();
171187
/a\u{1.1}b/u.test("au\{1.1\}b").echo();
172-
/a\u{110000}b/u.test("a" + (Array(110001).join('u')) +"b").echo();
173-
/a\u{11FFFF}b/u.test("au\{11FFFF\}b").echo();
188+
/a\u{110000}b/.test("a" + (Array(110001).join('u')) +"b").echo();
189+
/a\u{11FFFF}b/.test("au\{11FFFF\}b").echo();
174190
/a\u{10FFFF}b/.test("a\uDBFF\uDFFFb").echo();
175191

176-
/a\u{1000000}b/u.test("au\{1000000\}b").echo();
192+
/a\u{1000000}b/.test("au\{1000000\}b").echo();
177193
/a\u{1.1}b/u.test("a\u0001b").echo();
178194
/a\u{1}b/u.test("a\\ub").echo();
179195
/a\u{1}b/u.test("aub").echo();

0 commit comments

Comments
 (0)