Welcome! Log In Create A New Profile

Advanced

[njs] Fixed String.prototype.indexOf() for byte-strings.

Dmitry Volyntsev
August 26, 2020 11:00AM
details: https://hg.nginx.org/njs/rev/657d446001da
branches:
changeset: 1504:657d446001da
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Wed Aug 26 14:56:47 2020 +0000
description:
Fixed String.prototype.indexOf() for byte-strings.

The issue was introduced in e8a941b394a3 (0.4.3).

This closes #335 issue on Github.

diffstat:

src/njs_string.c | 6 +++---
src/test/njs_unit_test.c | 3 +++
2 files changed, 6 insertions(+), 3 deletions(-)

diffs (38 lines):

diff -r a2d12799c9f7 -r 657d446001da src/njs_string.c
--- a/src/njs_string.c Wed Aug 26 14:55:47 2020 +0000
+++ b/src/njs_string.c Wed Aug 26 14:56:47 2020 +0000
@@ -1999,7 +1999,7 @@ static njs_int_t
njs_string_prototype_index_of(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t unused)
{
- int64_t from;
+ int64_t from, length;
njs_int_t ret;
njs_value_t *this, *search, *pos, search_lvalue, pos_lvalue;
njs_string_prop_t string, s;
@@ -2029,10 +2029,10 @@ njs_string_prototype_index_of(njs_vm_t *
return ret;
}

- (void) njs_string_prop(&string, this);
+ length = njs_string_prop(&string, this);
(void) njs_string_prop(&s, search);

- from = njs_min(njs_max(from, 0), (int64_t) string.length);
+ from = njs_min(njs_max(from, 0), length);

njs_set_number(&vm->retval, njs_string_index_of(&string, &s, from));

diff -r a2d12799c9f7 -r 657d446001da src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed Aug 26 14:55:47 2020 +0000
+++ b/src/test/njs_unit_test.c Wed Aug 26 14:56:47 2020 +0000
@@ -7649,6 +7649,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var r = new String('undefined').indexOf(x); var x; r"),
njs_str("0") },

+ { njs_str("'a a'.toUTF8().indexOf('a', 1)"),
+ njs_str("2") },
+
{ njs_str("'abc'.lastIndexOf('abcdef')"),
njs_str("-1") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed String.prototype.indexOf() for byte-strings.

Dmitry Volyntsev 278 August 26, 2020 11:00AM



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

Online Users

Guests: 322
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