summaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
authorMattias Engdegård <mattiase@acm.org>2024-09-08 20:02:34 +0200
committerMattias Engdegård <mattiase@acm.org>2024-09-08 20:02:34 +0200
commite55e2e1c6baebbd105f930fa553ec65c74a3000d (patch)
treec171c29f7bcfb8a4a52e74e641506aaf9a2b960d /test/src
parent89c99891b2b3ab087cd7e824cef391ef26800ab4 (diff)
Make json-serialize always return a unibyte string (bug#70007)
The JSON format is defined as a byte sequence and will always be used as such, so returning a multibyte string makes little sense. * src/json.c (json_out_to_string): Remove. (Fjson_serialize): Return unibyte string. * test/src/json-tests.el (json-serialize/roundtrip) (json-serialize/roundtrip-scalars, json-serialize/string): Update tests. * doc/lispref/text.texi (Parsing JSON): Document. * etc/NEWS: Announce.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/json-tests.el50
1 files changed, 26 insertions, 24 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index ebac70fb1c7..1d7491a4593 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -36,7 +36,7 @@
(json
"[null,false,true,0,123,-456,3.75,\"abc\uFFFFαβγ𝔸𝐁𝖢\\\"\\\\\"]")
(json-bytes (encode-coding-string json 'utf-8)))
- (should (equal (json-serialize lisp) json)) ; or `json-bytes'?
+ (should (equal (json-serialize lisp) json-bytes))
(with-temp-buffer
;; multibyte buffer
(json-insert lisp)
@@ -82,28 +82,29 @@
"\"abc\uFFFFαβγ𝔸𝐁𝖢\\\"\\\\\"")))
(cl-destructuring-bind (lisp json) case
(ert-info ((format "%S ↔ %S" lisp json))
- (should (equal (json-serialize lisp) json))
- (with-temp-buffer
- (json-insert lisp)
- (should (equal (buffer-string) json))
- (should (eobp)))
- (with-temp-buffer
- (set-buffer-multibyte nil)
- (json-insert lisp)
- (should (equal (buffer-string) (encode-coding-string json 'utf-8)))
- (should (eobp)))
- (should (equal (json-parse-string json) lisp))
- (with-temp-buffer
- (insert json)
- (goto-char 1)
- (should (equal (json-parse-buffer) lisp))
- (should (eobp)))
- (with-temp-buffer
- (set-buffer-multibyte nil)
- (insert (encode-coding-string json 'utf-8))
- (goto-char 1)
- (should (equal (json-parse-buffer) lisp))
- (should (eobp)))))))
+ (let ((json-bytes (encode-coding-string json 'utf-8)))
+ (should (equal (json-serialize lisp) json-bytes))
+ (with-temp-buffer
+ (json-insert lisp)
+ (should (equal (buffer-string) json))
+ (should (eobp)))
+ (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (json-insert lisp)
+ (should (equal (buffer-string) (encode-coding-string json 'utf-8)))
+ (should (eobp)))
+ (should (equal (json-parse-string json) lisp))
+ (with-temp-buffer
+ (insert json)
+ (goto-char 1)
+ (should (equal (json-parse-buffer) lisp))
+ (should (eobp)))
+ (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (insert (encode-coding-string json 'utf-8))
+ (goto-char 1)
+ (should (equal (json-parse-buffer) lisp))
+ (should (eobp))))))))
(ert-deftest json-serialize/object ()
(let ((table (make-hash-table :test #'equal)))
@@ -226,7 +227,8 @@
(should (equal (json-serialize ["foo"]) "[\"foo\"]"))
(should (equal (json-serialize ["a\n\fb"]) "[\"a\\n\\fb\"]"))
(should (equal (json-serialize ["\nasdфыв\u001f\u007ffgh\t"])
- "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]"))
+ (encode-coding-string "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]"
+ 'utf-8)))
(should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]"))
(should-error (json-serialize ["\xC3\x84"]))
(should-error (json-serialize ["\u00C4\xC3\x84"])))