]> git.kaiwu.me - haproxy.git/commit
MINOR: log: add the +utf8 encoding option to let valid UTF-8 pass
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Sep 2026 03:21:40 +0000 (05:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Sep 2026 06:59:52 +0000 (08:59 +0200)
commit82a9570b3d8e02935450cf8f6adb3c32400322ac
tree9731e69730adee9c2c33147d102528bbb68976be
parent9375ed867e92e543ecb5a3c0053e05be6fd20f17
MINOR: log: add the +utf8 encoding option to let valid UTF-8 pass

Since commit db9492bcf ("BUG/MEDIUM: log: encode the whole non-printable
range in the +json output"), the +json encoder escapes every byte outside
the 32..126 range. This guarantees a pure ASCII output that cannot corrupt
a terminal, and it also purposely affects valid UTF-8 text: U+00E9,
encoded as 0xC3 0xA9, is logged as "\u00C3\u00A9", which a JSON decoder
turns into U+00C3 U+00A9. Some users relying on +json to log non-ASCII
text now get unreadable records.

User @Wahnes reported in GH issue #3512 that it breaks their use case
where UTF-8 was expected to land as-is in the output, as permitted by
RFC 8259. However, the patch above purposely avoided this because a
number of valid UTF-8 sequences can have effects on the terminal, such
as direction overrides (RTL/LTR), zero-width characters and a few others
that could affect how the text is rendered, and be used to hide actvities
if retrieved verbatim from header field values for example.

This patch adds a new "+utf8" log option that explicitly lets valid
UTF-8 pass unencoded in JSON, and only that, so that non-utf-8 bytes
above 126 remain encoded. The C1 class of control chars (0x80..0x9f)
which may appear encoded in UTF-8 (e.g. 0xc2 0x9b for 0x9b or \u009b)
remain encoded to protect terminals. This flag is stored in a new flag
LOG_OPT_UTF8 that is only used by LOG_OPT_ENCODE_JSON for now.

The doc and the regtest were updated accordingly.

This may be backported wherever db9492bcf is backported, along with the
previous commit, so that users of versions where it gets backported can
restore the ability to log UTF-8 text.
doc/configuration.txt
include/haproxy/log-t.h
reg-tests/log/log_json.vtc
src/log.c