From: Dmitry Volyntsev Date: Thu, 3 Sep 2020 13:30:15 +0000 (+0000) Subject: Fixed RegExp.prototype[Symbol.replace] when replace val is function. X-Git-Tag: 0.4.4~16 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=d8eaf8c339a6961a6c504ae0a4e8c231a9ec9338;p=njs.git Fixed RegExp.prototype[Symbol.replace] when replace val is function. Previously, a custom function received garbage value as the first argument. --- diff --git a/src/njs_regexp.c b/src/njs_regexp.c index 657f3733..ed9a1145 100644 --- a/src/njs_regexp.c +++ b/src/njs_regexp.c @@ -1347,6 +1347,7 @@ njs_regexp_prototype_symbol_replace(njs_vm_t *vm, njs_value_t *args, array = njs_array(r); arguments = array->start; + arguments[0] = matched; ncaptures = array->length; for (n = 1; n < ncaptures; n++) { diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 94c81c5f..a03a16ab 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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") },