[njs] Aligned StringIndexOf() implementation with the spec.

Dmitry Volyntsev xeioex at nginx.com
Wed May 22 16:40:57 UTC 2024


details:   https://hg.nginx.org/njs/rev/bc09b884022d
branches:  
changeset: 2334:bc09b884022d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue May 21 23:41:10 2024 -0700
description:
Aligned StringIndexOf() implementation with the spec.

When searchValue is empty the function should return early
when fromIndex <= len is also true.

diffstat:

 src/njs_string.c |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (14 lines):

diff -r 2d098d2a1c85 -r bc09b884022d src/njs_string.c
--- a/src/njs_string.c	Tue May 21 23:41:10 2024 -0700
+++ b/src/njs_string.c	Tue May 21 23:41:10 2024 -0700
@@ -1710,8 +1710,8 @@ njs_string_index_of(njs_string_prop_t *s
 
     length = string->length;
 
-    if (njs_slow_path(search->length == 0)) {
-        return (from < length) ? from : length;
+    if (search->length == 0 && from <= length) {
+        return from;
     }
 
     index = from;


More information about the nginx-devel mailing list