From 1d842ceccf86bbeef6beadc1efb8287c4a4518fe Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Tue, 2 Jul 2019 18:14:47 +0300 Subject: [PATCH] Fixed String.prototype.replace() for '$0' replacement string. For example: '0'.replace(/^/g, "$0") --- njs/njs_string.c | 2 +- njs/test/njs_unit_test.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/njs/njs_string.c b/njs/njs_string.c index ba4358c8..fa60e85c 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -3470,7 +3470,7 @@ skip: size = 2; - if (c >= '0' && c <= '9') { + if (c >= '1' && c <= '9') { type = c - '0'; if (p < end) { diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 81db47df..24ecf857 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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("/\\]/") }, -- 2.47.3