Welcome! Log In Create A New Profile

Advanced

[njs] Pass unprintable values to JSON.stringify() replacer function.

Dmitry Volyntsev
November 23, 2019 06:30AM
details: https://hg.nginx.org/njs/rev/cb81e4469b2c
branches:
changeset: 1254:cb81e4469b2c
user: Artem S. Povalyukhin <artem.povaluhin@gmail.com>
date: Sat Nov 23 12:52:06 2019 +0300
description:
Pass unprintable values to JSON.stringify() replacer function.

This closes #257 issue on Github.

diffstat:

src/njs_json.c | 14 +++++---------
src/test/njs_unit_test.c | 4 ++++
2 files changed, 9 insertions(+), 9 deletions(-)

diffs (45 lines):

diff -r 4367a0615234 -r cb81e4469b2c src/njs_json.c
--- a/src/njs_json.c Sat Nov 23 01:02:04 2019 +0300
+++ b/src/njs_json.c Sat Nov 23 12:52:06 2019 +0300
@@ -1211,14 +1211,6 @@ njs_json_stringify_iterator(njs_vm_t *vm
return ret;
}

- if (njs_is_undefined(value)
- || njs_is_symbol(value)
- || njs_is_function(value)
- || !njs_is_valid(value))
- {
- break;
- }
-
ret = njs_json_stringify_to_json(stringify, state, key, value);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
@@ -1229,7 +1221,11 @@ njs_json_stringify_iterator(njs_vm_t *vm
return ret;
}

- if (njs_is_undefined(value)) {
+ if (njs_is_undefined(value)
+ || njs_is_symbol(value)
+ || njs_is_function(value)
+ || !njs_is_valid(value))
+ {
break;
}

diff -r 4367a0615234 -r cb81e4469b2c src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Sat Nov 23 01:02:04 2019 +0300
+++ b/src/test/njs_unit_test.c Sat Nov 23 12:52:06 2019 +0300
@@ -14562,6 +14562,10 @@ static njs_unit_test_t njs_test[] =
"JSON.stringify(objs)"),
njs_str("[{\"\":{\"a\":1}},{\"a\":1}]") },

+ { njs_str("JSON.stringify({a: () => 1, b: Symbol(), c: undefined},"
+ "(k, v) => k.length ? String(v) : v)"),
+ njs_str("{\"a\":\"[object Function]\",\"b\":\"Symbol()\",\"c\":\"undefined\"}") },
+
{ njs_str("var a = []; a[0] = a; JSON.stringify(a)"),
njs_str("TypeError: Nested too deep or a cyclic structure") },

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

[njs] Pass unprintable values to JSON.stringify() replacer function.

Dmitry Volyntsev 53 November 23, 2019 06:30AM



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

Online Users

Guests: 78
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