diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
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.
Diffstat (limited to '')
-rw-r--r--source/html.c6
1 file changed, 6 insertions, 0 deletions
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;