From 00d1d8330338a789e701a5892fe2d05bab97cae9 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 18 Apr 2019 15:05:27 +0300 Subject: [PATCH] Shell: fixed njs_vm_value_dump() for empty string values. This closes #139 issue on Github. --- njs/njs_json.c | 14 ++++++++------ njs/test/njs_expect_test.exp | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/njs/njs_json.c b/njs/njs_json.c index 0573bd81..6f432b07 100644 --- a/njs/njs_json.c +++ b/njs/njs_json.c @@ -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; } diff --git a/njs/test/njs_expect_test.exp b/njs/test/njs_expect_test.exp index 722cb48e..bd5adc96 100644 --- a/njs/test/njs_expect_test.exp +++ b/njs/test/njs_expect_test.exp @@ -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" -- 2.47.3