emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8b52d9f5f1: Allow NUL characters in JSON input


From: Lars Ingebrigtsen
Subject: master 8b52d9f5f1: Allow NUL characters in JSON input
Date: Sat, 2 Jul 2022 09:07:04 -0400 (EDT)

branch: master
commit 8b52d9f5f177ce76b9ebecadd70c6dbbf07a20c6
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Allow NUL characters in JSON input
    
    * src/json.c (Fjson_parse_string, Fjson_parse_buffer): Allow NUL
    characters in JSON (bug#48274).
---
 src/json.c             | 6 ++++--
 test/src/json-tests.el | 7 +++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/json.c b/src/json.c
index 763f463aa4..9a455f507b 100644
--- a/src/json.c
+++ b/src/json.c
@@ -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)
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index f3dfeea30b..3560e1abc9 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]