Skip to content

Commit

Permalink
Merge pull request #100 from pygy/detect-brackets-braces-u
Browse files Browse the repository at this point in the history
Detect lone or unescaped brackets and braces when the unicode flag is set
  • Loading branch information
jviereck authored Feb 14, 2020
2 parents a6a47cc + d82c010 commit 0f22de3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@
var _char = matches[0];
var first = _char.charCodeAt(0);
if (hasUnicodeFlag) {
if (_char === '}') {
bail("unescaped or unmatched closing brace");
}
if (_char === ']') {
bail("unescaped or unmatched closing bracket");
}
var second;
if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) {
second = lookahead().charCodeAt(0);
Expand Down
18 changes: 18 additions & 0 deletions test/test-data-unicode.json
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,24 @@
"message": "atomEscape at position 1\n \\a\n ^",
"input": "\\a"
},
"\\-": {
"type": "error",
"name": "SyntaxError",
"message": "atomEscape at position 1\n \\-\n ^",
"input": "\\-"
},
"}": {
"type": "error",
"name": "SyntaxError",
"message": "unescaped or unmatched closing brace at position 1\n }\n ^",
"input": "}"
},
"]": {
"type": "error",
"name": "SyntaxError",
"message": "unescaped or unmatched closing bracket at position 1\n ]\n ^",
"input": "]"
},
"[\\-]": {
"type": "characterClass",
"body": [
Expand Down

0 comments on commit 0f22de3

Please sign in to comment.