October 27, 2016 09:52AM
details: http://hg.nginx.org/njs/rev/d84e34c2dbde
branches:
changeset: 225:d84e34c2dbde
user: Igor Sysoev <igor@sysoev.ru>
date: Thu Oct 27 16:38:05 2016 +0300
description:
String.prototype.lastIndexOf() method fix.

In collaboration with Valentin Bartenev.

diffstat:

njs/njs_string.c | 24 +++++++++++++-----------
1 files changed, 13 insertions(+), 11 deletions(-)

diffs (63 lines):

diff -r 86fd59307356 -r d84e34c2dbde njs/njs_string.c
--- a/njs/njs_string.c Thu Oct 27 11:14:46 2016 +0300
+++ b/njs/njs_string.c Thu Oct 27 16:38:05 2016 +0300
@@ -1290,12 +1290,14 @@ njs_string_prototype_last_index_of(njs_v
const u_char *p, *end;
njs_string_prop_t string, search;

+ index = -1;
+
if (nargs > 1) {
length = njs_string_prop(&string, &args[0]);
search_length = njs_string_prop(&search, &args[1]);

if (length < search_length) {
- goto small;
+ goto done;
}

index = NJS_STRING_MAX_LENGTH;
@@ -1328,10 +1330,10 @@ njs_string_prototype_last_index_of(njs_v
goto done;
}

- p--;
index--;
-
- } while (index >= 0);
+ p--;
+
+ } while (p >= string.start);

} else {
/* UTF-8 string. */
@@ -1345,22 +1347,22 @@ njs_string_prototype_last_index_of(njs_v
p = nxt_utf8_prev(p);
}

- do {
+ for ( ;; ) {
if (memcmp(p, search.start, search.size) == 0) {
goto done;
}

- p = nxt_utf8_prev(p);
index--;

- } while (index >= 0);
+ if (p <= string.start) {
+ break;
+ }
+
+ p = nxt_utf8_prev(p);
+ }
}
}

-small:
-
- index = -1;
-
done:

njs_number_set(&vm->retval, index);

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

[njs] String.prototype.lastIndexOf() method fix.

Igor Sysoev 1024 October 27, 2016 09:52AM



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

Online Users

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