[njs] Fixed RegExp.prototype.split().

Dmitry Volyntsev xeioex at nginx.com
Sat Oct 7 05:49:06 UTC 2023


details:   https://hg.nginx.org/njs/rev/c16f64d334f2
branches:  
changeset: 2217:c16f64d334f2
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Oct 06 16:49:59 2023 -0700
description:
Fixed RegExp.prototype.split().

The issue was introduced in c0aad58cfadb.

diffstat:

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

diffs (48 lines):

diff -r 632002c161b1 -r c16f64d334f2 src/njs_regexp.c
--- a/src/njs_regexp.c	Wed Oct 04 15:00:02 2023 -0700
+++ b/src/njs_regexp.c	Fri Oct 06 16:49:59 2023 -0700
@@ -1625,7 +1625,7 @@ njs_regexp_prototype_symbol_split(njs_vm
     njs_value_t        r, z, this, s_lvalue, setval, constructor;
     njs_object_t       *object;
     const u_char       *start, *end;
-    njs_string_prop_t  s;
+    njs_string_prop_t  s, sv;
     njs_value_t        arguments[2];
 
     static const njs_value_t  string_lindex = njs_string("lastIndex");
@@ -1815,14 +1815,17 @@ njs_regexp_prototype_symbol_split(njs_vm
         ncaptures = njs_max(ncaptures - 1, 0);
 
         for (i = 1; i <= ncaptures; i++) {
-            value = njs_array_push(vm, array);
-            if (njs_slow_path(value == NULL)) {
+            ret = njs_value_property_i64(vm, &z, i, retval);
+            if (njs_slow_path(ret == NJS_ERROR)) {
                 return NJS_ERROR;
             }
 
-            ret = njs_value_property_i64(vm, &z, i, value);
-            if (njs_slow_path(ret == NJS_ERROR)) {
-                return NJS_ERROR;
+            (void) njs_string_prop(&sv, retval);
+
+            ret = njs_array_string_add(vm, array, sv.start, sv.size,
+                                       sv.length);
+            if (njs_slow_path(ret != NJS_OK)) {
+                return ret;
             }
 
             if (array->length == limit) {
diff -r 632002c161b1 -r c16f64d334f2 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Oct 04 15:00:02 2023 -0700
+++ b/src/test/njs_unit_test.c	Fri Oct 06 16:49:59 2023 -0700
@@ -9734,6 +9734,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("'мояВерблюжьяСтрока'.split(/(?=[А-Я])/)"),
       njs_str("моя,Верблюжья,Строка") },
 
+    { njs_str("`aaaaaaaaaaaaaaaaa`.split(/(.*)/)"),
+      njs_str(",aaaaaaaaaaaaaaaaa,") },
+
     { njs_str("'Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '.split( /\\s*(?:;|$)\\s*/)"),
       njs_str("Harry Trump,Fred Barney,Helen Rigby,Bill Abel,Chris Hand,") },
 


More information about the nginx-devel mailing list