[njs] Fixed JSON.stringify() for arrays with empty cells.

Dmitry Volyntsev xeioex at nginx.com
Fri Apr 20 13:42:37 UTC 2018


details:   http://hg.nginx.org/njs/rev/cb7115e9fa1e
branches:  
changeset: 499:cb7115e9fa1e
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Apr 20 16:42:08 2018 +0300
description:
Fixed JSON.stringify() for arrays with empty cells.

diffstat:

 njs/njs_json.c           |  1 +
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)

diffs (24 lines):

diff -r 35486fa8c8b5 -r cb7115e9fa1e njs/njs_json.c
--- a/njs/njs_json.c	Wed Apr 11 17:31:53 2018 +0300
+++ b/njs/njs_json.c	Fri Apr 20 16:42:08 2018 +0300
@@ -1719,6 +1719,7 @@ njs_json_append_value(njs_json_stringify
 
     case NJS_VOID:
     case NJS_NULL:
+    case NJS_INVALID:
     case NJS_FUNCTION:
         return njs_json_buf_append(stringify, "null", 4);
 
diff -r 35486fa8c8b5 -r cb7115e9fa1e njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Apr 11 17:31:53 2018 +0300
+++ b/njs/test/njs_unit_test.c	Fri Apr 20 16:42:08 2018 +0300
@@ -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}") },
 


More information about the nginx-devel mailing list