diff options
| author | Philipp Stephani | 2017-12-23 17:56:36 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2017-12-30 23:16:51 +0100 |
| commit | a5835dfee139322de7aa071f1c87ef015acbecad (patch) | |
| tree | 992b5222049f2aa2a124f8c3484bbd074eaecfd1 /test/src | |
| parent | 30ffc256abe7443a02b44490c518baf9a122b4c8 (diff) | |
| download | emacs-a5835dfee139322de7aa071f1c87ef015acbecad.tar.gz emacs-a5835dfee139322de7aa071f1c87ef015acbecad.zip | |
Improve error reporting when serializing non-Unicode strings to JSON
* src/coding.c (utf8_string_p): New helper function.
(syms_of_coding) <utf-8-unix>: Move from json.c.
* src/json.c (json_check_utf8): New helper function.
(lisp_to_json_toplevel_1, lisp_to_json): Use it. To save a bit of
time, check for invalid UTF-8 strings only after encountering an
error, since Jansson already rejects them.
* test/src/json-tests.el (json-serialize/invalid-unicode): Adapt
expected error symbol.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/json-tests.el | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/test/src/json-tests.el b/test/src/json-tests.el index e394583bc76..107cab89083 100644 --- a/test/src/json-tests.el +++ b/test/src/json-tests.el | |||
| @@ -108,13 +108,11 @@ | |||
| 108 | 108 | ||
| 109 | (ert-deftest json-serialize/invalid-unicode () | 109 | (ert-deftest json-serialize/invalid-unicode () |
| 110 | (skip-unless (fboundp 'json-serialize)) | 110 | (skip-unless (fboundp 'json-serialize)) |
| 111 | ;; FIXME: "out of memory" is the wrong error signal, but we don't | 111 | (should-error (json-serialize ["a\uDBBBb"]) :type 'wrong-type-argument) |
| 112 | ;; currently distinguish between error types when serializing. | 112 | (should-error (json-serialize ["u\x110000v"]) :type 'wrong-type-argument) |
| 113 | (should-error (json-serialize ["a\uDBBBb"]) :type 'json-out-of-memory) | 113 | (should-error (json-serialize ["u\x3FFFFFv"]) :type 'wrong-type-argument) |
| 114 | (should-error (json-serialize ["u\x110000v"]) :type 'json-out-of-memory) | 114 | (should-error (json-serialize ["u\xCCv"]) :type 'wrong-type-argument) |
| 115 | (should-error (json-serialize ["u\x3FFFFFv"]) :type 'json-out-of-memory) | 115 | (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'wrong-type-argument)) |
| 116 | (should-error (json-serialize ["u\xCCv"]) :type 'json-out-of-memory) | ||
| 117 | (should-error (json-serialize ["u\u00C4\xCCv"]) :type 'json-out-of-memory)) | ||
| 118 | 116 | ||
| 119 | (ert-deftest json-parse-string/null () | 117 | (ert-deftest json-parse-string/null () |
| 120 | (skip-unless (fboundp 'json-parse-string)) | 118 | (skip-unless (fboundp 'json-parse-string)) |