Improve error reporting when serializing non-Unicode strings to JSON
commita5835dfee139322de7aa071f1c87ef015acbecad
authorPhilipp Stephani <phst@google.com>
Sat, 23 Dec 2017 16:56:36 +0000 (23 17:56 +0100)
committerPhilipp Stephani <phst@google.com>
Sat, 30 Dec 2017 22:16:51 +0000 (30 23:16 +0100)
tree992b5222049f2aa2a124f8c3484bbd074eaecfd1
parent30ffc256abe7443a02b44490c518baf9a122b4c8
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.
src/coding.c
src/coding.h
src/json.c
test/src/json-tests.el