Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit e31c47a

Browse files
dilijevkfarnung
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@a92d32a2d5
[1.8>1.9] [MERGE #4644 @dilijev] OS#15775563: Fix-up previous change. Explicitly allow RegExp identity escapes. Merge pull request #4644 from dilijev:fix_unicode_forbidden_escapes See #4637: Fix #4368: In unicode-mode RegExp, explicitly disallow invalid escapes. Fixes OS#15775563 Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
1 parent 21fb231 commit e31c47a

File tree

2 files changed

+113
-16
lines changed

2 files changed

+113
-16
lines changed

deps/chakrashim/core/lib/Parser/RegexParser.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,11 +1750,27 @@ namespace UnifiedRegex
17501750
}
17511751
// Take to be identity escape if ill-formed as per Annex B
17521752
break;
1753+
case '^':
1754+
case '$':
1755+
case '\\':
1756+
case '.':
1757+
case '*':
1758+
case '+':
1759+
case '?':
1760+
case '(':
1761+
case ')':
1762+
case '[':
1763+
case ']':
1764+
case '{':
1765+
case '}':
1766+
case '|':
1767+
case '/':
1768+
break; // fall-through for identity escape
17531769
default:
17541770
if (this->unicodeFlagPresent)
17551771
{
17561772
// As per #sec-forbidden-extensions, if unicode flag is present, we must disallow any other escape.
1757-
Js::JavascriptError::ThrowSyntaxError(scriptContext, JSERR_RegExpInvalidEscape);
1773+
this->Fail(JSERR_RegExpInvalidEscape); // throw SyntaxError
17581774
}
17591775
// As per Annex B, allow anything other than newlines and above. Embedded 0 is ok
17601776
break;

deps/chakrashim/core/test/Regex/unicode_forbidden_escapes.js

Lines changed: 96 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,110 @@
55

66
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
77

8+
let forbidden = [
9+
'\\p',
10+
'\\P',
11+
'\\a',
12+
'\\A',
13+
'\\e',
14+
'\\E',
15+
'\\y',
16+
'\\Y',
17+
'\\z',
18+
'\\Z',
19+
];
20+
21+
let identity = [
22+
"^",
23+
"$",
24+
"\\",
25+
".",
26+
"*",
27+
"+",
28+
"?",
29+
"(",
30+
")",
31+
"[",
32+
"]",
33+
"{",
34+
"}",
35+
"|",
36+
"/",
37+
];
38+
39+
let pseudoIdentity = [
40+
["f", "\f"],
41+
["n", "\n"],
42+
["r", "\r"],
43+
["t", "\t"],
44+
["v", "\v"],
45+
]
46+
847
var tests = [
948
{
10-
name: "Unicode-mode RegExp Forbidden Escapes",
49+
name: "Unicode-mode RegExp Forbidden Escapes (RegExp constructor)",
1150
body: function () {
12-
let forbidden = [
13-
'\\p',
14-
'\\P',
15-
'\\a',
16-
'\\A',
17-
'\\e',
18-
'\\E',
19-
'\\y',
20-
'\\Y',
21-
'\\z',
22-
'\\Z',
23-
];
24-
2551
for (re of forbidden) {
2652
assert.throws(function () { new RegExp(re, 'u') }, SyntaxError, 'Invalid regular expression: invalid escape in unicode pattern');
2753
assert.doesNotThrow(function () { new RegExp(re) });
2854
}
2955
}
30-
}
56+
},
57+
{
58+
name: "Unicode-mode RegExp Forbidden Escapes (literal)",
59+
body: function () {
60+
for (re of forbidden) {
61+
assert.throws(function () { eval(`/${re}/u`); }, SyntaxError, 'Invalid regular expression: invalid escape in unicode pattern');
62+
assert.doesNotThrow(function () { eval(`/${re}/`); }, SyntaxError, 'Invalid regular expression: invalid escape in unicode pattern');
63+
}
64+
}
65+
},
66+
{
67+
name: "Allow IdentityEscapes (RegExp constructor)",
68+
body: function () {
69+
for (c of identity) {
70+
assert.doesNotThrow(function () { new RegExp(`\\${c}`, 'u') });
71+
assert.doesNotThrow(function () { new RegExp(`\\${c}`) });
72+
}
73+
}
74+
},
75+
{
76+
name: "Allow IdentityEscapes (literal)",
77+
body: function () {
78+
for (c of identity) {
79+
assert.doesNotThrow(function () { eval(`/\\${c}/u`); });
80+
assert.doesNotThrow(function () { eval(`/\\${c}/`); });
81+
}
82+
}
83+
},
84+
{
85+
name: "Allow Pseudo-Identity Escapes (RegExpconstructor)",
86+
body: function () {
87+
for (test of pseudoIdentity) {
88+
let c = test[0];
89+
let rendered = test[1];
90+
let re;
91+
assert.doesNotThrow(function () { re = new RegExp(`\\${c}`, 'u') });
92+
assert.isTrue(re.test(rendered));
93+
assert.doesNotThrow(function () { re = new RegExp(`\\${c}`) });
94+
assert.isTrue(re.test(rendered));
95+
}
96+
}
97+
},
98+
{
99+
name: "Allow Pseudo-Identity Escapes (literal)",
100+
body: function () {
101+
for (test of pseudoIdentity) {
102+
let c = test[0];
103+
let rendered = test[1];
104+
let re;
105+
assert.doesNotThrow(function () { re = eval(`/\\${c}/u`) });
106+
assert.isTrue(re.test(rendered));
107+
assert.doesNotThrow(function () { re = eval(`/\\${c}/`) });
108+
assert.isTrue(re.test(rendered));
109+
}
110+
}
111+
},
31112
];
32113

33114
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)