]> git.kaiwu.me - njs.git/commitdiff
Aligned StringIndexOf() implementation with the spec.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 22 May 2024 06:41:10 +0000 (23:41 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 22 May 2024 06:41:10 +0000 (23:41 -0700)
When searchValue is empty the function should return early
when fromIndex <= len is also true.

src/njs_string.c

index 4ef162df0a131d57b76ed7ddd0146c4c89aa2da9..9551427429e5adfab0ef6b1b04be759e02e18859 100644 (file)
@@ -1710,8 +1710,8 @@ njs_string_index_of(njs_string_prop_t *string, njs_string_prop_t *search,
 
     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;