Skip to content

Commit b7a641c

Browse files
authored
Raw string length should be adjusted when UTF8 string is converted to CESU8 (#3853)
This patch fixes #3812. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 4c53c94 commit b7a641c

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

jerry-core/parser/js/js-lexer.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
915915
lexer_string_options_t opts) /**< options */
916916
{
917917
#if ENABLED (JERRY_ES2015)
918-
size_t raw_length_dec = 0;
918+
int32_t raw_length_adjust = 0;
919919
#else /* ENABLED (JERRY_ES2015) */
920920
JERRY_UNUSED (opts);
921921
#endif /* ENABLED (JERRY_ES2015) */
@@ -972,7 +972,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
972972
&& *source_p == LIT_CHAR_LF)
973973
{
974974
#if ENABLED (JERRY_ES2015)
975-
raw_length_dec++;
975+
raw_length_adjust--;
976976
#endif /* ENABLED (JERRY_ES2015) */
977977
source_p++;
978978
}
@@ -1121,7 +1121,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
11211121
source_p + 1 < source_end_p &&
11221122
source_p[1] == LIT_CHAR_LEFT_BRACE)
11231123
{
1124-
raw_length_dec++;
1124+
raw_length_adjust--;
11251125
source_p++;
11261126
break;
11271127
}
@@ -1135,6 +1135,9 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
11351135
length += 2 * 3;
11361136
has_escape = true;
11371137
source_p += 4;
1138+
#if ENABLED (JERRY_ES2015)
1139+
raw_length_adjust += 2;
1140+
#endif /* ENABLED (JERRY_ES2015) */
11381141
column++;
11391142
continue;
11401143
}
@@ -1158,7 +1161,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
11581161
&& *source_p == LIT_CHAR_LF)
11591162
{
11601163
source_p++;
1161-
raw_length_dec++;
1164+
raw_length_adjust--;
11621165
}
11631166
line++;
11641167
column = 1;
@@ -1206,7 +1209,7 @@ lexer_parse_string (parser_context_t *context_p, /**< context */
12061209
#if ENABLED (JERRY_ES2015)
12071210
if (opts & LEXER_STRING_RAW)
12081211
{
1209-
length = (size_t) (source_p - string_start_p) - raw_length_dec;
1212+
length = (size_t) ((source_p - string_start_p) + raw_length_adjust);
12101213
}
12111214
#endif /* ENABLED (JERRY_ES2015) */
12121215

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function f (a) {
16+
assert(a[0] === '𞹴');
17+
}
18+
19+
f`𞹴`;

0 commit comments

Comments
 (0)