From 0868c5d358fcbf1d872ca2302194cb2908557360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 25 Oct 2024 13:55:42 -0400 Subject: [PATCH] annex-b: \ can be ClassAtomNoDash if followed by c --- parser.js | 6 ++++++ test/test-data-unicode.json | 6 ++++++ test/test-data.json | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/parser.js b/parser.js index 5f7aa1f..dbd11e3 100644 --- a/parser.js +++ b/parser.js @@ -1386,6 +1386,9 @@ // ClassAtomNoDash :: // SourceCharacter but not one of \ or ] or - // \ ClassEscape + // + // ClassAtomNoDash (Annex B):: + // \ [lookahead = c] var res; if (res = matchReg(/^[^\\\]-]/)) { @@ -1393,6 +1396,9 @@ } else if (match('\\')) { res = parseClassEscape(); if (!res) { + if (!isUnicodeMode && lookahead() == 'c') { + return createCharacter('\\'); + } bail('classEscape'); } diff --git a/test/test-data-unicode.json b/test/test-data-unicode.json index 0eaac11..402a390 100644 --- a/test/test-data-unicode.json +++ b/test/test-data-unicode.json @@ -1872,5 +1872,11 @@ "name": "SyntaxError", "message": "Expected atom at position 2\n \\B{1}\n ^", "input": "\\B{1}" + }, + "[\\c]": { + "type": "error", + "name": "SyntaxError", + "message": "classEscape at position 2\n [\\c]\n ^", + "input": "[\\c]" } } diff --git a/test/test-data.json b/test/test-data.json index 1151c5e..dbd6a84 100644 --- a/test/test-data.json +++ b/test/test-data.json @@ -38627,6 +38627,38 @@ ], "raw": ".(?!.){2,3}" }, + "[\\c]": { + "type": "characterClass", + "kind": "union", + "body": [ + { + "type": "value", + "kind": "symbol", + "codePoint": 92, + "range": [ + 1, + 2 + ], + "raw": "\\" + }, + { + "type": "value", + "kind": "symbol", + "codePoint": 99, + "range": [ + 2, + 3 + ], + "raw": "c" + } + ], + "negative": false, + "range": [ + 0, + 4 + ], + "raw": "[\\c]" + }, "^*": { "type": "error", "name": "SyntaxError",