From: Dmitry Volyntsev Date: Wed, 26 Feb 2020 14:48:46 +0000 (+0300) Subject: Fixed Unicode Escaping in JSON.stringify() according to spec. X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=04d001d5137a1ec85a5679e294cc4f2d3dd7554a;p=njs.git Fixed Unicode Escaping in JSON.stringify() according to spec. Lowecase hexadecimal number are required. --- diff --git a/src/njs_json.c b/src/njs_json.c index a7df7cd4..7369b174 100644 --- a/src/njs_json.c +++ b/src/njs_json.c @@ -1610,7 +1610,7 @@ njs_json_append_string(njs_chb_t *chain, const njs_value_t *value, char quote) njs_string_prop_t string; static char hex2char[16] = { '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; (void) njs_string_prop(&string, value); @@ -1619,7 +1619,7 @@ njs_json_append_string(njs_chb_t *chain, const njs_value_t *value, char quote) utf8 = (string.length != 0 && string.length != string.size); size = njs_max(string.size + 2, 7); - dst = njs_chb_reserve(chain, string.size + 2); + dst = njs_chb_reserve(chain, size); if (njs_slow_path(dst == NULL)) { return; } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 9fbfe39c..087435f7 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -15612,7 +15612,7 @@ static njs_unit_test_t njs_test[] = njs_str("\"\\n\\t\\r\\\"\\f\\b\"") }, { njs_str("JSON.stringify('\x00\x01\x02\x1f')"), - njs_str("\"\\u0000\\u0001\\u0002\\u001F\"") }, + njs_str("\"\\u0000\\u0001\\u0002\\u001f\"") }, { njs_str("JSON.stringify('abc\x00')"), njs_str("\"abc\\u0000\"") },