From 2832bdc94d4224fea129c09b29cd5f7634ea7d15 Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Tue, 28 Jul 2020 15:53:17 +0200 Subject: [PATCH] Fix surrogate pair lookahead in String.prototype.toUpper (#4073) This patch fixes #4013. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- .../ecma-builtin-string-prototype.c | 3 ++- tests/jerry/es.next/regression-test-issue-4013.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/jerry/es.next/regression-test-issue-4013.js diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index b8d0a17f6..2827b9680 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -1002,7 +1002,8 @@ ecma_builtin_string_prototype_object_conversion_helper (ecma_string_t *input_str lit_code_point_t cp = lit_cesu8_read_next (&input_curr_p); #if ENABLED (JERRY_ESNEXT) - if (lit_is_code_point_utf16_high_surrogate (cp)) + if (lit_is_code_point_utf16_high_surrogate (cp) + && input_curr_p < input_str_end_p) { const ecma_char_t next_ch = lit_cesu8_peek_next (input_curr_p); if (lit_is_code_point_utf16_low_surrogate (next_ch)) diff --git a/tests/jerry/es.next/regression-test-issue-4013.js b/tests/jerry/es.next/regression-test-issue-4013.js new file mode 100644 index 000000000..4b45b83d9 --- /dev/null +++ b/tests/jerry/es.next/regression-test-issue-4013.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. + +assert("\ud800".toUpperCase() === "\ud800");