[njs] Fixed String.prototype.replace() for '$0' replacement string.

Alexander Borisov alexander.borisov at nginx.com
Tue Jul 2 15:15:04 UTC 2019


details:   https://hg.nginx.org/njs/rev/0f2d18a5eed3
branches:  
changeset: 1025:0f2d18a5eed3
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Tue Jul 02 18:14:47 2019 +0300
description:
Fixed String.prototype.replace() for '$0' replacement string.

For example:
'0'.replace(/^/g, "$0")

diffstat:

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

diffs (25 lines):

diff -r 4a0f6ff54f88 -r 0f2d18a5eed3 njs/njs_string.c
--- a/njs/njs_string.c	Mon Jul 01 22:44:14 2019 +0300
+++ b/njs/njs_string.c	Tue Jul 02 18:14:47 2019 +0300
@@ -3470,7 +3470,7 @@ skip:
 
         size = 2;
 
-        if (c >= '0' && c <= '9') {
+        if (c >= '1' && c <= '9') {
             type = c - '0';
 
             if (p < end) {
diff -r 4a0f6ff54f88 -r 0f2d18a5eed3 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Mon Jul 01 22:44:14 2019 +0300
+++ b/njs/test/njs_unit_test.c	Tue Jul 02 18:14:47 2019 +0300
@@ -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("/\\]/") },
 


More information about the nginx-devel mailing list