[njs] Fixed parsing of "$&" substitutions in String.prototype.replace().

Alexander Borisov alexander.borisov at nginx.com
Tue Jul 16 14:32:51 UTC 2019


details:   https://hg.nginx.org/njs/rev/738f2410b532
branches:  
changeset: 1054:738f2410b532
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Tue Jul 16 17:32:11 2019 +0300
description:
Fixed parsing of "$&" substitutions in String.prototype.replace().

diffstat:

 njs/njs_string.c         |  3 ---
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diffs (26 lines):

diff -r 8ac396f1a20c -r 738f2410b532 njs/njs_string.c
--- a/njs/njs_string.c	Tue Jul 16 17:32:11 2019 +0300
+++ b/njs/njs_string.c	Tue Jul 16 17:32:11 2019 +0300
@@ -3513,9 +3513,6 @@ skip:
 
             type *= 2;
 
-        } else if (c == '&') {
-            type = 0;
-
         } else if (c == '`') {
             type = NJS_SUBST_PRECEDING;
 
diff -r 8ac396f1a20c -r 738f2410b532 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jul 16 17:32:11 2019 +0300
+++ b/njs/test/njs_unit_test.c	Tue Jul 16 17:32:11 2019 +0300
@@ -5684,6 +5684,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("typeof String.bytesFrom(Array(15).fill(0xE3)).replace(/^/g, 1)"),
       nxt_string("string") },
 
+    { nxt_string("typeof '0'.replace(/^/g, '$&')"),
+      nxt_string("string") },
+
     { nxt_string("/]/"),
       nxt_string("/\\]/") },
 


More information about the nginx-devel mailing list