[njs] Fixed RegExp.prototype[Symbol.replace] when replace val is function.
Dmitry Volyntsev
xeioex at nginx.com
Thu Sep 3 13:30:50 UTC 2020
details: https://hg.nginx.org/njs/rev/2bae88c33583
branches:
changeset: 1515:2bae88c33583
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Sep 03 13:30:15 2020 +0000
description:
Fixed RegExp.prototype[Symbol.replace] when replace val is function.
Previously, a custom function received garbage value as the first
argument.
diffstat:
src/njs_regexp.c | 1 +
src/test/njs_unit_test.c | 4 ++++
2 files changed, 5 insertions(+), 0 deletions(-)
diffs (25 lines):
diff -r e03701b6e8aa -r 2bae88c33583 src/njs_regexp.c
--- a/src/njs_regexp.c Tue Sep 01 17:25:33 2020 +0000
+++ b/src/njs_regexp.c Thu Sep 03 13:30:15 2020 +0000
@@ -1347,6 +1347,7 @@ njs_regexp_prototype_symbol_replace(njs_
array = njs_array(r);
arguments = array->start;
+ arguments[0] = matched;
ncaptures = array->length;
for (n = 1; n < ncaptures; n++) {
diff -r e03701b6e8aa -r 2bae88c33583 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Sep 01 17:25:33 2020 +0000
+++ b/src/test/njs_unit_test.c Thu Sep 03 13:30:15 2020 +0000
@@ -8307,6 +8307,10 @@ static njs_unit_test_t njs_test[] =
{ njs_str("RegExp.prototype[Symbol.replace].call(/b/, 'abc','B')"),
njs_str("aBc") },
+ { njs_str("var m; var r = /./; r.exec = function() { return []; };"
+ "r[Symbol.replace]('foo', function() {m = arguments[0]}); [m, typeof m]"),
+ njs_str("undefined,string") },
+
{ njs_str("String.bytesFrom([253,242,141,10]).replace(/\\s/g, 'X')[3]"),
njs_str("X") },
More information about the nginx-devel
mailing list