Skip to content

Commit

Permalink
fix: throw on unescaped class set reserved double punctuator
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 26, 2024
1 parent 743fca0 commit af5ee57
Show file tree
Hide file tree
Showing 3 changed files with 729 additions and 70 deletions.
3 changes: 3 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,9 @@
// ...

var res;
if (matchReg(/^(?:&&|!!|##|\$\$|%%|\*\*|\+\+|,,|\.\.|::|;;|<<|==|>>|\?\?|@@|\^\^|``|~~)/)) {
bail('Invalid set operation in character class');
}
if (res = matchReg(/^[^()[\]{}/\-\\|]/)) {
return createCharacter(res);
}
Expand Down
188 changes: 118 additions & 70 deletions test/test-data-unicode-set.json
Original file line number Diff line number Diff line change
Expand Up @@ -914,76 +914,10 @@
"raw": "[[a-z]&&[p-s]]"
},
"[AB&&CD]": {
"type": "characterClass",
"kind": "union",
"body": [
{
"type": "value",
"kind": "symbol",
"codePoint": 65,
"range": [
1,
2
],
"raw": "A"
},
{
"type": "value",
"kind": "symbol",
"codePoint": 66,
"range": [
2,
3
],
"raw": "B"
},
{
"type": "value",
"kind": "symbol",
"codePoint": 38,
"range": [
3,
4
],
"raw": "&"
},
{
"type": "value",
"kind": "symbol",
"codePoint": 38,
"range": [
4,
5
],
"raw": "&"
},
{
"type": "value",
"kind": "symbol",
"codePoint": 67,
"range": [
5,
6
],
"raw": "C"
},
{
"type": "value",
"kind": "symbol",
"codePoint": 68,
"range": [
6,
7
],
"raw": "D"
}
],
"negative": false,
"range": [
0,
8
],
"raw": "[AB&&CD]"
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 5\n [AB&&CD]\n ^",
"input": "[AB&&CD]"
},
"[AB--CD]": {
"type": "error",
Expand Down Expand Up @@ -1579,5 +1513,119 @@
"name": "SyntaxError",
"message": "Invalid escape at position 1: \\_\n [\\__]\n ^",
"input": "[\\__]"
},
"[&&]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [&&]\n ^",
"input": "[&&]"
},
"[!!]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [!!]\n ^",
"input": "[!!]"
},
"[##]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [##]\n ^",
"input": "[##]"
},
"[$$]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [$$]\n ^",
"input": "[$$]"
},
"[%%]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [%%]\n ^",
"input": "[%%]"
},
"[**]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [**]\n ^",
"input": "[**]"
},
"[++]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [++]\n ^",
"input": "[++]"
},
"[,,]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [,,]\n ^",
"input": "[,,]"
},
"[..]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [..]\n ^",
"input": "[..]"
},
"[::]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [::]\n ^",
"input": "[::]"
},
"[;;]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [;;]\n ^",
"input": "[;;]"
},
"[<<]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [<<]\n ^",
"input": "[<<]"
},
"[==]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [==]\n ^",
"input": "[==]"
},
"[>>]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [>>]\n ^",
"input": "[>>]"
},
"[??]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [??]\n ^",
"input": "[??]"
},
"[@@]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [@@]\n ^",
"input": "[@@]"
},
"[^^^]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 4\n [^^^]\n ^",
"input": "[^^^]"
},
"[``]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [``]\n ^",
"input": "[``]"
},
"[~~]": {
"type": "error",
"name": "SyntaxError",
"message": "Invalid set operation in character class at position 3\n [~~]\n ^",
"input": "[~~]"
}
}
Loading

0 comments on commit af5ee57

Please sign in to comment.