From 0c6a92b3389c7c24cd6be9b5a46d295b247e88c5 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Tue, 7 Feb 2023 10:28:54 +0800 Subject: [PATCH] fixed e4ba215 from https://gitee.com/gavin1012_hw/ark_ts2abc/pulls/829 Fix bracket validation in ParseUnicodePropertyEscape Issue:I6DCWS Signed-off-by: gavin1012_hw Change-Id: Ib659ecd0a599c41f8ced5dad316f874ea3e775c5 --- es2panda/lexer/regexp/regexp.cpp | 2 +- .../test/parser/js/test-regexp-p-expected.txt | 71 +++++++++++++++++++ es2panda/test/parser/js/test-regexp-p.js | 16 +++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 es2panda/test/parser/js/test-regexp-p-expected.txt create mode 100644 es2panda/test/parser/js/test-regexp-p.js diff --git a/es2panda/lexer/regexp/regexp.cpp b/es2panda/lexer/regexp/regexp.cpp index 630555df54..ea4356ce4d 100644 --- a/es2panda/lexer/regexp/regexp.cpp +++ b/es2panda/lexer/regexp/regexp.cpp @@ -680,7 +680,7 @@ void RegExpParser::ParseUnicodePropertyEscape() } char32_t ch = Next(); - if (ch == LEX_CHAR_LEFT_BRACE) { + if (ch == LEX_CHAR_RIGHT_BRACE) { break; } diff --git a/es2panda/test/parser/js/test-regexp-p-expected.txt b/es2panda/test/parser/js/test-regexp-p-expected.txt new file mode 100644 index 0000000000..31af86465c --- /dev/null +++ b/es2panda/test/parser/js/test-regexp-p-expected.txt @@ -0,0 +1,71 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "RegularExpressionLiteral", + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "right": { + "type": "RegExpLiteral", + "source": "\u200C\u200D\p{ID_Continue}", + "flags": "u", + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 59 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 16, + "column": 59 + } + } +} diff --git a/es2panda/test/parser/js/test-regexp-p.js b/es2panda/test/parser/js/test-regexp-p.js new file mode 100644 index 0000000000..d2e67d9dd0 --- /dev/null +++ b/es2panda/test/parser/js/test-regexp-p.js @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +RegularExpressionLiteral = /\u200C\u200D\p{ID_Continue}/u; \ No newline at end of file -- Gitee