]> git.kaiwu.me - njs.git/commitdiff
Fixed parsing of "$&" substitutions in String.prototype.replace().
authorAlexander Borisov <alexander.borisov@nginx.com>
Tue, 16 Jul 2019 14:32:11 +0000 (17:32 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Tue, 16 Jul 2019 14:32:11 +0000 (17:32 +0300)
njs/njs_string.c
njs/test/njs_unit_test.c

index 69d2f49246d3d7ea8e48cbfbe82126adc189d503..e4ddd1281b55fa18ce7405d234fe59b5b33a12e2 100644 (file)
@@ -3513,9 +3513,6 @@ skip:
 
             type *= 2;
 
-        } else if (c == '&') {
-            type = 0;
-
         } else if (c == '`') {
             type = NJS_SUBST_PRECEDING;
 
index eecb0a242bfb806aca0f577c869a737699aad35c..860ab5a966360cdd8c77bef1d2a1f8a9548dd502 100644 (file)
@@ -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("/\\]/") },