From: Philipp Stephani Date: Fri, 22 Dec 2017 01:35:16 +0000 (+0100) Subject: Add a few more unit tests for JSON X-Git-Tag: emacs-27.0.90~5984 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9ced53ae8b381afbdd465081c7f82ebfd03be47b;p=emacs.git Add a few more unit tests for JSON * test/src/json-tests.el (json-serialize/invalid-unicode) (json-parse-string/null): Add more tests. (json-parse-string/invalid-unicode): New test. --- diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 71aa4a8b783..9884e9a2d57 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el @@ -88,13 +88,35 @@ ;; currently distinguish between error types when serializing. (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory) (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory) + (should-error (json-serialize ["u\x3FFFFFv"]) :type 'json-out-of-memory) (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory)) (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)) +(ert-deftest json-parse-string/invalid-unicode () + "Some examples from +https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt." + (skip-unless (fboundp 'json-parse-string)) + ;; Invalid UTF-8 code unit sequences. + (should-error (json-parse-string "[\"\x80\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\xBF\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\xFE\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\xC0\xAF\"]") :type 'json-parse-error) + (should-error (json-parse-string "[\"\xC0\x80\"]") :type 'json-parse-error) + ;; Surrogates. + (should-error (json-parse-string "[\"\uDB7F\"]") + :type 'json-parse-error) + (should-error (json-parse-string "[\"\xED\xAD\xBF\"]") + :type 'json-parse-error) + (should-error (json-parse-string "[\"\uDB7F\uDFFF\"]") + :type 'json-parse-error) + (should-error (json-parse-string "[\"\xED\xAD\xBF\xED\xBF\xBF\"]") + :type 'json-parse-error)) + (ert-deftest json-parse-string/incomplete () (skip-unless (fboundp 'json-parse-string)) (should-error (json-parse-string "[123") :type 'json-end-of-file))