Skip to content

Commit 5517b6c

Browse files
authored
disallow quantifiable anchors in unicode mode (#135)
1 parent c622da7 commit 5517b6c

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed

parser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,21 @@
598598

599599
quantifier = parseQuantifier() || false;
600600
if (quantifier) {
601+
var type = anchorOrAtom.type, behavior = anchorOrAtom.behavior;
602+
if (
603+
type === "group" &&
604+
(behavior === "negativeLookbehind" ||
605+
behavior === "lookbehind" ||
606+
(isUnicodeMode &&
607+
(behavior === "negativeLookahead" || behavior === "lookahead")))
608+
) {
609+
bail(
610+
"Invalid quantifier",
611+
"",
612+
quantifier.range[0],
613+
quantifier.range[1]
614+
);
615+
}
601616
quantifier.body = flattenBody(anchorOrAtom);
602617
// The quantifier contains the atom. Therefore, the beginning of the
603618
// quantifier range is given by the beginning of the atom.

test/test-data-lookbehind.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,5 +359,17 @@
359359
"name": "SyntaxError",
360360
"message": "atomEscape at position 1\n \\k\n ^",
361361
"input": "\\k"
362+
},
363+
"(?<=.){2,3}": {
364+
"type": "error",
365+
"name": "SyntaxError",
366+
"message": "Invalid quantifier at position 6\n (?<=.){2,3}\n ^",
367+
"input": "(?<=.){2,3}"
368+
},
369+
"(?<!.){2,3}": {
370+
"type": "error",
371+
"name": "SyntaxError",
372+
"message": "Invalid quantifier at position 6\n (?<!.){2,3}\n ^",
373+
"input": "(?<!.){2,3}"
362374
}
363375
}

test/test-data-unicode-set.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,5 +1561,17 @@
15611561
21
15621562
],
15631563
"raw": "[\\u{14630}-\\u{14633}]"
1564+
},
1565+
".(?=.){2,3}": {
1566+
"type": "error",
1567+
"name": "SyntaxError",
1568+
"message": "Invalid quantifier at position 6\n .(?=.){2,3}\n ^",
1569+
"input": ".(?=.){2,3}"
1570+
},
1571+
".(?!.){2,3}": {
1572+
"type": "error",
1573+
"name": "SyntaxError",
1574+
"message": "Invalid quantifier at position 6\n .(?!.){2,3}\n ^",
1575+
"input": ".(?!.){2,3}"
15641576
}
15651577
}

test/test-data-unicode.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,5 +1228,17 @@
12281228
"name": "SyntaxError",
12291229
"message": "Invalid decimal escape in unicode mode at position 1\n \\2(.)\n ^",
12301230
"input": "\\2(.)"
1231+
},
1232+
".(?=.){2,3}": {
1233+
"type": "error",
1234+
"name": "SyntaxError",
1235+
"message": "Invalid quantifier at position 6\n .(?=.){2,3}\n ^",
1236+
"input": ".(?=.){2,3}"
1237+
},
1238+
".(?!.){2,3}": {
1239+
"type": "error",
1240+
"name": "SyntaxError",
1241+
"message": "Invalid quantifier at position 6\n .(?!.){2,3}\n ^",
1242+
"input": ".(?!.){2,3}"
12311243
}
12321244
}

test/test-data.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38524,5 +38524,107 @@
3852438524
6
3852538525
],
3852638526
"raw": "(?=a)?"
38527+
},
38528+
".(?=.){2,3}": {
38529+
"type": "alternative",
38530+
"body": [
38531+
{
38532+
"type": "dot",
38533+
"range": [
38534+
0,
38535+
1
38536+
],
38537+
"raw": "."
38538+
},
38539+
{
38540+
"type": "quantifier",
38541+
"min": 2,
38542+
"max": 3,
38543+
"greedy": true,
38544+
"body": [
38545+
{
38546+
"type": "group",
38547+
"behavior": "lookahead",
38548+
"body": [
38549+
{
38550+
"type": "dot",
38551+
"range": [
38552+
4,
38553+
5
38554+
],
38555+
"raw": "."
38556+
}
38557+
],
38558+
"range": [
38559+
1,
38560+
6
38561+
],
38562+
"raw": "(?=.)"
38563+
}
38564+
],
38565+
"symbol": null,
38566+
"range": [
38567+
1,
38568+
11
38569+
],
38570+
"raw": "(?=.){2,3}"
38571+
}
38572+
],
38573+
"range": [
38574+
0,
38575+
11
38576+
],
38577+
"raw": ".(?=.){2,3}"
38578+
},
38579+
".(?!.){2,3}": {
38580+
"type": "alternative",
38581+
"body": [
38582+
{
38583+
"type": "dot",
38584+
"range": [
38585+
0,
38586+
1
38587+
],
38588+
"raw": "."
38589+
},
38590+
{
38591+
"type": "quantifier",
38592+
"min": 2,
38593+
"max": 3,
38594+
"greedy": true,
38595+
"body": [
38596+
{
38597+
"type": "group",
38598+
"behavior": "negativeLookahead",
38599+
"body": [
38600+
{
38601+
"type": "dot",
38602+
"range": [
38603+
4,
38604+
5
38605+
],
38606+
"raw": "."
38607+
}
38608+
],
38609+
"range": [
38610+
1,
38611+
6
38612+
],
38613+
"raw": "(?!.)"
38614+
}
38615+
],
38616+
"symbol": null,
38617+
"range": [
38618+
1,
38619+
11
38620+
],
38621+
"raw": "(?!.){2,3}"
38622+
}
38623+
],
38624+
"range": [
38625+
0,
38626+
11
38627+
],
38628+
"raw": ".(?!.){2,3}"
3852738629
}
3852838630
}

0 commit comments

Comments
 (0)