diff options
| author | Philipp Stephani | 2021-02-13 14:25:42 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2021-02-13 14:37:19 +0100 |
| commit | 625de7e403abb24c2d6ae417622fa8c7d6f55530 (patch) | |
| tree | 9e8f67fff1a1551922a5f9ba297269e2118ce199 /test/src/json-tests.el | |
| parent | 856502d80d0a3ccfe8c80b65290fdb00e8813391 (diff) | |
| download | emacs-625de7e403abb24c2d6ae417622fa8c7d6f55530.tar.gz emacs-625de7e403abb24c2d6ae417622fa8c7d6f55530.zip | |
Allow any JSON value at the top level (Bug#42994).
Newer standards like RFC 8259, which obsoletes the earlier RFC 4627,
now allow any top-level value unconditionally, so Emacs should too.
* src/json.c (Fjson_serialize, Fjson_insert): Pass JSON_ENCODE_ANY to
allow serialization of any JSON value. Call 'lisp_to_json' instead of
'lisp_to_json_toplevel'. Remove obsolete comments
(neither JSON_DECODE_ANY nor JSON_ALLOW_NUL are allowed here). Reword
documentation strings.
(Fjson_parse_string, Fjson_parse_buffer): Pass JSON_DECODE_ANY to
allow deserialization of any JSON value. Reword documentation
strings.
(lisp_to_json_nonscalar, lisp_to_json_nonscalar_1): Rename from
"toplevel" to avoid confusion.
(lisp_to_json): Adapt caller.
* test/src/json-tests.el (json-serialize/roundtrip-scalars): New unit
test.
* doc/lispref/text.texi (Parsing JSON): Update documentation.
Diffstat (limited to 'test/src/json-tests.el')
| -rw-r--r-- | test/src/json-tests.el | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 4be11b8c81a..908945fcb08 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el | |||
| @@ -51,6 +51,34 @@ | |||
| 51 | (should (equal (json-parse-buffer) lisp)) | 51 | (should (equal (json-parse-buffer) lisp)) |
| 52 | (should (eobp))))) | 52 | (should (eobp))))) |
| 53 | 53 | ||
| 54 | (ert-deftest json-serialize/roundtrip-scalars () | ||
| 55 | "Check that Bug#42994 is fixed." | ||
| 56 | (skip-unless (fboundp 'json-serialize)) | ||
| 57 | (dolist (case '((:null "null") | ||
| 58 | (:false "false") | ||
| 59 | (t "true") | ||
| 60 | (0 "0") | ||
| 61 | (123 "123") | ||
| 62 | (-456 "-456") | ||
| 63 | (3.75 "3.75") | ||
| 64 | ;; The noncharacter U+FFFF should be passed through, | ||
| 65 | ;; cf. https://www.unicode.org/faq/private_use.html#noncharacters. | ||
| 66 | ("abc\uFFFFαβγ𝔸𝐁𝖢\"\\" | ||
| 67 | "\"abc\uFFFFαβγ𝔸𝐁𝖢\\\"\\\\\""))) | ||
| 68 | (cl-destructuring-bind (lisp json) case | ||
| 69 | (ert-info ((format "%S ↔ %S" lisp json)) | ||
| 70 | (should (equal (json-serialize lisp) json)) | ||
| 71 | (with-temp-buffer | ||
| 72 | (json-insert lisp) | ||
| 73 | (should (equal (buffer-string) json)) | ||
| 74 | (should (eobp))) | ||
| 75 | (should (equal (json-parse-string json) lisp)) | ||
| 76 | (with-temp-buffer | ||
| 77 | (insert json) | ||
| 78 | (goto-char 1) | ||
| 79 | (should (equal (json-parse-buffer) lisp)) | ||
| 80 | (should (eobp))))))) | ||
| 81 | |||
| 54 | (ert-deftest json-serialize/object () | 82 | (ert-deftest json-serialize/object () |
| 55 | (skip-unless (fboundp 'json-serialize)) | 83 | (skip-unless (fboundp 'json-serialize)) |
| 56 | (let ((table (make-hash-table :test #'equal))) | 84 | (let ((table (make-hash-table :test #'equal))) |