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. + +/኱𞻲/‌ஃ︠﹍