From 19b8a5cb887039f31d3531208834548970de668f Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Fri, 20 Apr 2018 16:42:08 +0300 Subject: [PATCH] Fixed JSON.stringify() for arrays with empty cells. --- njs/njs_json.c | 1 + njs/test/njs_unit_test.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/njs/njs_json.c b/njs/njs_json.c index 9ad86d0c..c7b952f9 100644 --- a/njs/njs_json.c +++ b/njs/njs_json.c @@ -1719,6 +1719,7 @@ njs_json_append_value(njs_json_stringify_t *stringify, njs_value_t *value) case NJS_VOID: case NJS_NULL: + case NJS_INVALID: case NJS_FUNCTION: return njs_json_buf_append(stringify, "null", 4); diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 693dd856..7fbee6a0 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -8673,6 +8673,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("JSON.stringify([])"), nxt_string("[]") }, + { nxt_string("var a = [1]; a[2] = 'x'; JSON.stringify(a)"), + nxt_string("[1,null,\"x\"]") }, + { nxt_string("JSON.stringify({a:\"b\",c:19,e:null,t:true,f:false})"), nxt_string("{\"a\":\"b\",\"c\":19,\"e\":null,\"t\":true,\"f\":false}") }, -- 2.47.3