Welcome! Log In Create A New Profile

Advanced

[njs] Fixed template literal from producing byte-strings.

Dmitry Volyntsev
June 09, 2022 03:10AM
details: https://hg.nginx.org/njs/rev/d4cdb9085e4d
branches:
changeset: 1880:d4cdb9085e4d
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Wed Jun 08 21:06:16 2022 -0700
description:
Fixed template literal from producing byte-strings.

Previously, as a side effect of creating a key for the values hash a
byte-string was created. This byte-string was reused internally and
might appear in template literal. As a result a byte-string was
produced as a value for a template literal. Byte-strings are obsolete
and are scheduled for removal because they can cause issues with
internal routines not prepared for them.

diffstat:

src/njs_generator.c | 10 ++++++++--
src/test/njs_unit_test.c | 4 ++++
2 files changed, 12 insertions(+), 2 deletions(-)

diffs (41 lines):

diff -r cf267407eabe -r d4cdb9085e4d src/njs_generator.c
--- a/src/njs_generator.c Tue Jun 07 21:30:57 2022 -0700
+++ b/src/njs_generator.c Wed Jun 08 21:06:16 2022 -0700
@@ -4756,6 +4756,7 @@ static njs_int_t
njs_generate_global_reference(njs_vm_t *vm, njs_generator_t *generator,
njs_parser_node_t *node, njs_bool_t exception)
{
+ ssize_t length;
njs_int_t ret;
njs_index_t index;
njs_value_t property;
@@ -4783,8 +4784,13 @@ njs_generate_global_reference(njs_vm_t *
return NJS_ERROR;
}

- ret = njs_string_set(vm, &property, lex_entry->name.start,
- lex_entry->name.length);
+ length = njs_utf8_length(lex_entry->name.start, lex_entry->name.length);
+ if (njs_slow_path(length < 0)) {
+ return NJS_ERROR;
+ }
+
+ ret = njs_string_new(vm, &property, lex_entry->name.start,
+ lex_entry->name.length, length);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
diff -r cf267407eabe -r d4cdb9085e4d src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Jun 07 21:30:57 2022 -0700
+++ b/src/test/njs_unit_test.c Wed Jun 08 21:06:16 2022 -0700
@@ -7174,6 +7174,10 @@ static njs_unit_test_t njs_test[] =
{ njs_str("`\\${a}bc"),
njs_str("SyntaxError: Unterminated template literal in 1") },

+ { njs_str("var v = undefined; var u8 = 'α';"
+ "[`undefined${u8}`.length, `undefineQ${u8}`.length]"),
+ njs_str("10,10") },
+
{ njs_str("`text1\ntext2`;"),
njs_str("text1\ntext2") },

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed template literal from producing byte-strings.

Dmitry Volyntsev 378 June 09, 2022 03:10AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 312
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready