From 5e6ec75f384d60c244798190bf2799c67451d5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Thu, 13 Feb 2020 12:36:29 +0100 Subject: [PATCH 1/2] Add tests for lone and unescaped closing braces and brackets --- test/test-data-unicode.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test-data-unicode.json b/test/test-data-unicode.json index fcc9d23..6b2e16b 100644 --- a/test/test-data-unicode.json +++ b/test/test-data-unicode.json @@ -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": [ From d82c010df2d54c4847082a94e41d169b66beccb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Thu, 13 Feb 2020 12:38:11 +0100 Subject: [PATCH 2/2] Detect lone or unmatched brackets and braces when the unicode flag is set --- parser.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parser.js b/parser.js index 74b5670..68849f0 100644 --- a/parser.js +++ b/parser.js @@ -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);