got-notify-http: fix unicode handling
commitea5e974da9b1047689411a00ecc0a9c1fb101d73
authorOmar Polo <op@omarpolo.com>
Thu, 28 Mar 2024 09:41:18 +0000 (28 09:41 +0000)
committerOmar Polo <op@omarpolo.com>
Thu, 28 Mar 2024 09:41:18 +0000 (28 09:41 +0000)
treefa98ab3680f2558132244e5f8ad79cfc396e00ee
parent87890bc26c1c6958bd64bb9d46fbc29ba6a92d95
got-notify-http: fix unicode handling

JSON strings are made of UNICODE codepoints, of which only \, " and
control characters have to be escaped, and the whole document MUST
be encoded in UTF-8.  The current code generates invalid strings
for non-ASCII characters, so it has to be made UTF-8 aware.

tedu' isu8cont() can't be used since it allows surrogate pairs and
overlong sequences which will cause decoding errors on the receiving
side.  Similarly, mbtowc() depends on the current locale and could
cause issues in -portable.

Instead, bundle Björn Höhrmann's "Flexible and Economical UTF-8
Decoder" and use it to parse the text.  Decoding errors results in
the replacement character U+FFFD being emitted and the bytes
considered so far to be discarded; the decoder is then restarted
with the next byte.

Git commit messages don't carry the notion of the encoding, but
it's reasonable to expect UTF-8 (which is a superset of ASCII).
For other more esotic encodings, the commit id can be used to
manually extract the data.

ok stsp@
gotd/libexec/got-notify-http/got-notify-http.c
gotd/libexec/got-notify-http/utf8d.h [new file with mode: 0644]
regress/gotd/http_notification.sh