From 0559036fb6e64ec25d3a1ff707925fe1cdce5f05 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 12:53:16 -1000 Subject: Cut text between characters, never inside one The index description was cut at a byte count, which could split a multibyte character and leave an invalid sequence on the page. Commit subjects already backed up to the start of the character, so html_ntxt now does that for every caller. --- source/html.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/html.c') diff --git a/source/html.c b/source/html.c index 1a6b7c5..b6e62a6 100644 --- a/source/html.c +++ b/source/html.c @@ -247,6 +247,12 @@ ssize_t html_ntxt(const char *txt, size_t len) } p++; } + // A cut inside a multibyte character would leave an invalid sequence + // on the page, so it backs up to where that character starts. The + // escaped bytes are all ASCII, so no character spans one. + if (left < 0) + while (p > txt && (*p & 0xC0) == 0x80) + p--; if (p != txt) html_raw(txt, p - txt); return left; -- cgit