1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-16 17:19:41 +00:00

Allow NUL characters in JSON input

* src/json.c (Fjson_parse_string, Fjson_parse_buffer): Allow NUL
characters in JSON (bug#48274).
This commit is contained in:
Lars Ingebrigtsen 2022-07-02 15:06:24 +02:00
parent 5b112482fb
commit 8b52d9f5f1
2 changed files with 9 additions and 4 deletions

View File

@ -975,7 +975,7 @@ usage: (json-parse-string STRING &rest ARGS) */)
json_error_t error;
json_t *object
= json_loads (SSDATA (encoded), JSON_DECODE_ANY, &error);
= json_loads (SSDATA (encoded), JSON_DECODE_ANY | JSON_ALLOW_NUL, &error);
if (object == NULL)
json_parse_error (&error);
@ -1071,7 +1071,9 @@ usage: (json-parse-buffer &rest args) */)
json_error_t error;
json_t *object
= json_load_callback (json_read_buffer_callback, &data,
JSON_DECODE_ANY | JSON_DISABLE_EOF_CHECK,
JSON_DECODE_ANY
| JSON_DISABLE_EOF_CHECK
| JSON_ALLOW_NUL,
&error);
if (object == NULL)

View File

@ -187,8 +187,11 @@
(ert-deftest json-parse-string/null ()
(skip-unless (fboundp 'json-parse-string))
(should-error (json-parse-string "\x00") :type 'wrong-type-argument)
;; FIXME: Reconsider whether this is the right behavior.
(should-error (json-parse-string "[\"a\\u0000b\"]") :type 'json-parse-error))
(should (json-parse-string "[\"a\\u0000b\"]"))
(let* ((string "{\"foo\":\"this is a string including a literal \\u0000\"}")
(data (json-parse-string string)))
(should (hash-table-p data))
(should (equal string (json-serialize data)))))
(ert-deftest json-parse-string/invalid-unicode ()
"Some examples from