From 7770b6237ad8e8fbc94917f4cf088b1bc9707597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Lang=C3=B3?= Date: Tue, 23 May 2017 12:04:11 +0200 Subject: [PATCH] Fix parsing of UTF-8 RegExp literals (#1840) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1831 JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com --- jerry-core/parser/js/js-lexer.c | 14 +++++++++++++- tests/jerry/fail/regression-test-issue-1831.js | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/jerry/fail/regression-test-issue-1831.js diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index f7bd5b952..699dd8c42 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -1821,7 +1821,19 @@ lexer_construct_regexp_object (parser_context_t *context_p, /**< context */ const re_compiled_code_t *re_bytecode_p = NULL; ecma_value_t completion_value; - ecma_string_t *pattern_str_p = ecma_new_ecma_string_from_utf8 (regex_start_p, length); + ecma_string_t *pattern_str_p = NULL; + + if (lit_is_valid_cesu8_string (regex_start_p, length)) + { + pattern_str_p = ecma_new_ecma_string_from_utf8 (regex_start_p, length); + } + else + { + JERRY_ASSERT (lit_is_valid_utf8_string (regex_start_p, length)); + pattern_str_p = ecma_new_ecma_string_from_utf8_converted_to_cesu8 (regex_start_p, length); + } + + completion_value = re_compile_bytecode (&re_bytecode_p, pattern_str_p, current_flags); diff --git a/tests/jerry/fail/regression-test-issue-1831.js b/tests/jerry/fail/regression-test-issue-1831.js new file mode 100644 index 000000000..26b5ebf75 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-1831.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// 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. + +/኱𞻲/‌ஃ︠﹍