From 89053095eb70eff4527dfc3052d517eeb07fc816 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Thu, 1 Jan 2026 16:27:21 +0100 Subject: truncate rss title at utf8 char boundary Advance a whole utf8 char at a time while looking for where to truncate the title. --- RELEASE_NOTES.md | 2 ++ rss.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7e5b722..174b873 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,8 @@ ## UNRELEASED +Truncate RSS titles at UTF-8 character boundaries (contributed by lxo). + Link contacts to single-user people pages. Also, user's posts are shown (contributed by lxo). Added emoji reactions (contributed by violette). diff --git a/rss.c b/rss.c index 6124e7a..09446dc 100644 --- a/rss.c +++ b/rss.c @@ -10,6 +10,7 @@ #include "xs_openssl.h" #include "xs_json.h" #include "xs_http.h" +#include "xs_unicode.h" #include "snac.h" @@ -74,7 +75,14 @@ xs_str *rss_from_timeline(snac *user, const xs_list *timeline, title = xs_regex_replace_i(title, "&[^;]+;", " "); int i; - for (i = 0; title[i] && title[i] != '\n' && i < 50; i++); + for (i = 0; title[i] && title[i] != '\n' && i < 50; ) { + const char *p = &title[i]; + unsigned int cp = xs_utf8_dec(&p); + int n = p - title; + if (cp == 0xfffd || n > 50) + break; + i = n; + } if (title[i] != '\0') { title[i] = '\0'; -- cgit v1.2.3