Welcome! Log In Create A New Profile

Advanced

[njs] Fixed RegExp.prototype[Symbol.replace] when replace val is function.

Dmitry Volyntsev
September 03, 2020 09:32AM
details: https://hg.nginx.org/njs/rev/2bae88c33583
branches:
changeset: 1515:2bae88c33583
user: Dmitry Volyntsev <xeioex@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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed RegExp.prototype[Symbol.replace] when replace val is function.

Dmitry Volyntsev 110 September 03, 2020 09:32AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 64
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready