]> git.kaiwu.me - njs.git/commitdiff
Fixed String.prototype.replace() for '$0' replacement string.
authorAlexander Borisov <alexander.borisov@nginx.com>
Tue, 2 Jul 2019 15:14:47 +0000 (18:14 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Tue, 2 Jul 2019 15:14:47 +0000 (18:14 +0300)
For example:
'0'.replace(/^/g, "$0")

njs/njs_string.c
njs/test/njs_unit_test.c

index ba4358c8a8af0dc47653c5d6f8e89785d0ea188e..fa60e85cea03462240622df671e3c4539065ae91 100644 (file)
@@ -3470,7 +3470,7 @@ skip:
 
         size = 2;
 
-        if (c >= '0' && c <= '9') {
+        if (c >= '1' && c <= '9') {
             type = c - '0';
 
             if (p < end) {
index 81db47df7df421649563191a387a672e0a64be74..24ecf85793195f0d02bb11bb9484982feb2a5424 100644 (file)
@@ -5566,6 +5566,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("'abc'.replace(/(a*)/g, function v0() {return '124'})"),
       nxt_string("124124b124c124") },
 
+    { nxt_string("typeof '0'.replace(/^/g, '$0')"),
+      nxt_string("string") },
+
     { nxt_string("/]/"),
       nxt_string("/\\]/") },