]> git.kaiwu.me - njs.git/commitdiff
Shell: fixed njs_vm_value_dump() for empty string values.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 18 Apr 2019 12:05:27 +0000 (15:05 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 18 Apr 2019 12:05:27 +0000 (15:05 +0300)
This closes #139 issue on Github.

njs/njs_json.c
njs/test/njs_expect_test.exp

index 0573bd810b5022469b85ad51570d70a36c90527b..6f432b074fe33db1fbf9a6b3a01b3e4ded613080 100644 (file)
@@ -1961,14 +1961,16 @@ njs_json_buf_append(njs_json_stringify_t *stringify, const char *msg,
 {
     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);
+        memcpy(p, msg, len);
 
-    njs_json_buf_written(stringify, len);
+        njs_json_buf_written(stringify, len);
+    }
 
     return NXT_OK;
 }
index 722cb48e370d00ef792b594b4ab74cb457596c52..bd5adc96a12c983a97e32da4f7f1bf17f6391844 100644 (file)
@@ -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"