Welcome! Log In Create A New Profile

Advanced

[njs] Fix in String.indexOf() and String.lastIndexOf() functions.

June 01, 2016 09:22AM
details: http://hg.nginx.org/njs/rev/1c96b24bcdd2
branches:
changeset: 111:1c96b24bcdd2
user: Igor Sysoev <igor@sysoev.ru>
date: Fri Apr 29 17:02:52 2016 +0300
description:
Fix in String.indexOf() and String.lastIndexOf() functions.

diffstat:

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

diffs (53 lines):

diff -r 169958fd3f70 -r 1c96b24bcdd2 njs/njs_string.c
--- a/njs/njs_string.c Mon Apr 25 19:30:27 2016 +0300
+++ b/njs/njs_string.c Fri Apr 29 17:02:52 2016 +0300
@@ -1192,25 +1192,36 @@ njs_string_index_of(njs_vm_t *vm, njs_va

if (index < length) {

- p = string.start;
- end = p + string.size;
-
if (string.size == length) {
/* Byte or ASCII string. */
- p += index;
+ p = string.start + index;
+ end = (string.start + string.size) - (search.size - 1);
+
+ while (p < end) {
+ if (memcmp(p, search.start, search.size) == 0) {
+ return index;
+ }
+
+ index++;
+ p++;
+ }

} else {
/* UTF-8 string. */
- p = njs_string_offset(p, end, index);
- }
-
- while (p < end) {
- if (memcmp(p, search.start, search.size) == 0) {
- return index;
+ end = string.start + string.size;
+
+ p = njs_string_offset(string.start, end, index);
+
+ end -= search.size - 1;
+
+ while (p < end) {
+ if (memcmp(p, search.start, search.size) == 0) {
+ return index;
+ }
+
+ index++;
+ p = nxt_utf8_next(p, end);
}
-
- index++;
- p = nxt_utf8_next(p, end);
}

} else if (search.size == 0) {

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

[njs] Fix in String.indexOf() and String.lastIndexOf() functions.

Igor Sysoev 689 June 01, 2016 09:22AM



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

Online Users

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