[njs] Shell: fixed njs_vm_value_dump() for empty string values.

Dmitry Volyntsev xeioex at nginx.com
Thu Apr 18 12:20:12 UTC 2019


details:   https://hg.nginx.org/njs/rev/108ef0cd302d
branches:  
changeset: 901:108ef0cd302d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Apr 18 15:05:27 2019 +0300
description:
Shell: fixed njs_vm_value_dump() for empty string values.

This closes #139 issue on Github.

diffstat:

 njs/njs_json.c               |  16 +++++++++-------
 njs/test/njs_expect_test.exp |   2 ++
 2 files changed, 11 insertions(+), 7 deletions(-)

diffs (40 lines):

diff -r 9c67f7d03672 -r 108ef0cd302d njs/njs_json.c
--- a/njs/njs_json.c	Wed Apr 17 21:12:21 2019 +0300
+++ b/njs/njs_json.c	Thu Apr 18 15:05:27 2019 +0300
@@ -1961,15 +1961,17 @@ njs_json_buf_append(njs_json_stringify_t
 {
     u_char  *p;
 
-    p = njs_json_buf_reserve(stringify, len);
-    if (nxt_slow_path(p == NULL)) {
-        return NXT_ERROR;
+    if (len != 0) {
+        p = njs_json_buf_reserve(stringify, len);
+        if (nxt_slow_path(p == NULL)) {
+            return NXT_ERROR;
+        }
+
+        memcpy(p, msg, len);
+
+        njs_json_buf_written(stringify, len);
     }
 
-    memcpy(p, msg, len);
-
-    njs_json_buf_written(stringify, len);
-
     return NXT_OK;
 }
 
diff -r 9c67f7d03672 -r 108ef0cd302d njs/test/njs_expect_test.exp
--- a/njs/test/njs_expect_test.exp	Wed Apr 17 21:12:21 2019 +0300
+++ b/njs/test/njs_expect_test.exp	Thu Apr 18 15:05:27 2019 +0300
@@ -188,6 +188,8 @@ njs_test {
 njs_test {
     {"console.log()\r\n"
      "console.log()\r\nundefined\r\n>> "}
+    {"console.log('')\r\n"
+     "console.log('')\r\n\r\nundefined\r\n>> "}
     {"console.log(1)\r\n"
      "console.log(1)\r\n1\r\nundefined\r\n>> "}
     {"console.log(1, 'a')\r\n"


More information about the nginx-devel mailing list