diff options
| author | Lars Ingebrigtsen | 2022-07-02 15:06:24 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-07-02 15:06:24 +0200 |
| commit | 8b52d9f5f177ce76b9ebecadd70c6dbbf07a20c6 (patch) | |
| tree | 1ce43ea5c48e09dbbdb0d5659acc2c9f81cce032 | |
| parent | 5b112482fbdb0351487a7af592ae901e20ec45c1 (diff) | |
| download | emacs-8b52d9f5f177ce76b9ebecadd70c6dbbf07a20c6.tar.gz emacs-8b52d9f5f177ce76b9ebecadd70c6dbbf07a20c6.zip | |
Allow NUL characters in JSON input
* src/json.c (Fjson_parse_string, Fjson_parse_buffer): Allow NUL
characters in JSON (bug#48274).
| -rw-r--r-- | src/json.c | 6 | ||||
| -rw-r--r-- | test/src/json-tests.el | 7 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/json.c b/src/json.c index 763f463aa4e..9a455f507b4 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -975,7 +975,7 @@ usage: (json-parse-string STRING &rest ARGS) */) | |||
| 975 | 975 | ||
| 976 | json_error_t error; | 976 | json_error_t error; |
| 977 | json_t *object | 977 | json_t *object |
| 978 | = json_loads (SSDATA (encoded), JSON_DECODE_ANY, &error); | 978 | = json_loads (SSDATA (encoded), JSON_DECODE_ANY | JSON_ALLOW_NUL, &error); |
| 979 | if (object == NULL) | 979 | if (object == NULL) |
| 980 | json_parse_error (&error); | 980 | json_parse_error (&error); |
| 981 | 981 | ||
| @@ -1071,7 +1071,9 @@ usage: (json-parse-buffer &rest args) */) | |||
| 1071 | json_error_t error; | 1071 | json_error_t error; |
| 1072 | json_t *object | 1072 | json_t *object |
| 1073 | = json_load_callback (json_read_buffer_callback, &data, | 1073 | = json_load_callback (json_read_buffer_callback, &data, |
| 1074 | JSON_DECODE_ANY | JSON_DISABLE_EOF_CHECK, | 1074 | JSON_DECODE_ANY |
| 1075 | | JSON_DISABLE_EOF_CHECK | ||
| 1076 | | JSON_ALLOW_NUL, | ||
| 1075 | &error); | 1077 | &error); |
| 1076 | 1078 | ||
| 1077 | if (object == NULL) | 1079 | if (object == NULL) |
diff --git a/test/src/json-tests.el b/test/src/json-tests.el index f3dfeea30b4..3560e1abc96 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el | |||
| @@ -187,8 +187,11 @@ | |||
| 187 | (ert-deftest json-parse-string/null () | 187 | (ert-deftest json-parse-string/null () |
| 188 | (skip-unless (fboundp 'json-parse-string)) | 188 | (skip-unless (fboundp 'json-parse-string)) |
| 189 | (should-error (json-parse-string "\x00") :type 'wrong-type-argument) | 189 | (should-error (json-parse-string "\x00") :type 'wrong-type-argument) |
| 190 | ;; FIXME: Reconsider whether this is the right behavior. | 190 | (should (json-parse-string "[\"a\\u0000b\"]")) |
| 191 | (should-error (json-parse-string "[\"a\\u0000b\"]") :type 'json-parse-error)) | 191 | (let* ((string "{\"foo\":\"this is a string including a literal \\u0000\"}") |
| 192 | (data (json-parse-string string))) | ||
| 193 | (should (hash-table-p data)) | ||
| 194 | (should (equal string (json-serialize data))))) | ||
| 192 | 195 | ||
| 193 | (ert-deftest json-parse-string/invalid-unicode () | 196 | (ert-deftest json-parse-string/invalid-unicode () |
| 194 | "Some examples from | 197 | "Some examples from |