From: Dmitry Volyntsev Date: Thu, 18 Apr 2019 12:05:27 +0000 (+0300) Subject: Shell: fixed njs_vm_value_dump() for empty string values. X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=00d1d8330338a789e701a5892fe2d05bab97cae9;p=njs.git Shell: fixed njs_vm_value_dump() for empty string values. This closes #139 issue on Github. --- 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"