emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 994ce51: JSON: Add tests for Unicode edge cases


From: Philipp Stephani
Subject: [Emacs-diffs] master 994ce51: JSON: Add tests for Unicode edge cases
Date: Mon, 18 Dec 2017 18:11:15 -0500 (EST)

branch: master
commit 994ce51b28384bb2ea7a88248a105fcdc7c53a7b
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    JSON: Add tests for Unicode edge cases
    
    * test/src/json-tests.el (json-serialize/string): Add test for
    serializing the null character.
    (json-parse-string/null): Add test for parsing the null character.
    (json-serialize/invalid-unicode): Add tests for invalid Unicode
    strings.
    (json-serialize/roundtrip): Add Unicode
    noncharacter, non-BMP characters, and syntactic characters.
---
 test/src/json-tests.el | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 07eb41d..551f8ac 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -28,8 +28,10 @@
 
 (ert-deftest json-serialize/roundtrip ()
   (skip-unless (fboundp 'json-serialize))
-  (let ((lisp [:null :false t 0 123 -456 3.75 "abcαβγ"])
-        (json "[null,false,true,0,123,-456,3.75,\"abcαβγ\"]"))
+  ;; The noncharacter U+FFFF should be passed through,
+  ;; cf. https://www.unicode.org/faq/private_use.html#noncharacters.
+  (let ((lisp [:null :false t 0 123 -456 3.75 "abc\uFFFFαβγ𝔸𝐁𝖢\"\\"])
+        (json "[null,false,true,0,123,-456,3.75,\"abc\uFFFFαβγ𝔸𝐁𝖢\\\"\\\\\"]"))
     (should (equal (json-serialize lisp) json))
     (with-temp-buffer
       (json-insert lisp)
@@ -75,7 +77,22 @@
   (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\"]")))
+                 "[\"\\nasdфыв\\u001F\u007ffgh\\t\"]"))
+  (should (equal (json-serialize ["a\0b"]) "[\"a\\u0000b\"]")))
+
+(ert-deftest json-serialize/invalid-unicode ()
+  (skip-unless (fboundp 'json-serialize))
+  ;; FIXME: "out of memory" is the wrong error signal, but we don't
+  ;; currently distinguish between error types when serializing.
+  (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory)
+  (should-error (json-serialize (vector (string ?a #x110000 ?b)))
+                :type 'json-out-of-memory)
+  (should-error (json-serialize ["a\xCCb"] :type 'json-out-of-memory)))
+
+(ert-deftest json-parse-string/null ()
+  (skip-unless (fboundp 'json-parse-string))
+  ;; FIXME: Reconsider whether this is the right behavior.
+  (should-error (json-parse-string "[a\\u0000b]") :type 'json-parse-error))
 
 (ert-deftest json-parse-string/incomplete ()
   (skip-unless (fboundp 'json-parse-string))



reply via email to

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