shared/json: reject non-utf-8 strings
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 30 Aug 2020 17:52:10 +0000 (19:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Sep 2020 14:48:40 +0000 (16:48 +0200)
commitea9afe0064adbcc5ff7c8d44026e996f4c8e3e89
tree60206c5869dc8b0c7fe07505f4feeca59b492f39
parent80ab31a43577ab95eb3ddfac637bd792989555b1
shared/json: reject non-utf-8 strings

JSON strings must be utf-8-clean. We also verify this in json_parse_string()
so we would reject a message with invalid utf-8 anyway.

It would probably be slightly cheaper to detect non-conformaning strings in
serialization, but then we'd have to fail serialization. By doing this early,
we give the caller a chance to handle the error nicely.

The test is adjusted to contain a valid utf-8 string after decoding of the
utf-32 encoding in json ("विवेकख्यातिरविप्लवा हानोपायः।", something about the
cessation of ignorance).
src/shared/json.c
src/test/test-json.c