]> git.kaiwu.me - njs.git/commitdiff
Fixed Unicode Escaping in JSON.stringify() according to spec.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 26 Feb 2020 14:48:46 +0000 (17:48 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 26 Feb 2020 14:48:46 +0000 (17:48 +0300)
Lowecase hexadecimal number are required.

src/njs_json.c
src/test/njs_unit_test.c

index a7df7cd4285e43b31b51cc374a1718a38c4ba0c5..7369b174fcafd3a33e0920baf94c7bf41cfbb12a 100644 (file)
@@ -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;
     }
index 9fbfe39c6d6229dc3b5488107f14c3541450bd58..087435f73c0a60be38870adf358ed2f54229604f 100644 (file)
@@ -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\"") },