* src/json.c (Fjson_parse_string, Fjson_parse_buffer): Allow NUL
characters in JSON (bug#48274).
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);
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)
(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