]> git.kaiwu.me - njs.git/commitdiff
Fixed RegExp.prototype[Symbol.replace] when replace val is function.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 3 Sep 2020 13:30:15 +0000 (13:30 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 3 Sep 2020 13:30:15 +0000 (13:30 +0000)
Previously, a custom function received garbage value as the first
argument.

src/njs_regexp.c
src/test/njs_unit_test.c

index 657f3733effad9c33f78464bde52976701b77e1c..ed9a11458bf42f70e2362ca345f3d2d2d123c0b8 100644 (file)
@@ -1347,6 +1347,7 @@ njs_regexp_prototype_symbol_replace(njs_vm_t *vm, njs_value_t *args,
             array = njs_array(r);
 
             arguments = array->start;
+            arguments[0] = matched;
             ncaptures = array->length;
 
             for (n = 1; n < ncaptures; n++) {
index 94c81c5f3fce3e8ed942fb84178efdba526d377a..a03a16abcbba5f7352c169f8b05b178fa716192f 100644 (file)
@@ -8307,6 +8307,10 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("RegExp.prototype[Symbol.replace].call(/b/, 'abc','B')"),
       njs_str("aBc") },
 
+    { njs_str("var m; var r = /./; r.exec = function() { return []; };"
+              "r[Symbol.replace]('foo', function() {m = arguments[0]}); [m, typeof m]"),
+      njs_str("undefined,string") },
+
     { njs_str("String.bytesFrom([253,242,141,10]).replace(/\\s/g, 'X')[3]"),
       njs_str("X") },