commit 8905309

Alexandre Oliva  ·  2026-01-01 15:27:21 +0000 UTC
parent 20eba6f
truncate rss title at utf8 char boundary

Advance a whole utf8 char at a time while looking for where to
truncate the title.
2 files changed,  +11, -1
M rss.c
+2, -0
1@@ -2,6 +2,8 @@
2 
3 ## UNRELEASED
4 
5+Truncate RSS titles at UTF-8 character boundaries (contributed by lxo).
6+
7 Link contacts to single-user people pages. Also, user's posts are shown (contributed by lxo).
8 
9 Added emoji reactions (contributed by violette).
M rss.c
+9, -1
 1@@ -10,6 +10,7 @@
 2 #include "xs_openssl.h"
 3 #include "xs_json.h"
 4 #include "xs_http.h"
 5+#include "xs_unicode.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -74,7 +75,14 @@ xs_str *rss_from_timeline(snac *user, const xs_list *timeline,
10         title = xs_regex_replace_i(title, "&[^;]+;", " ");
11         int i;
12 
13-        for (i = 0; title[i] && title[i] != '\n' && i < 50; i++);
14+        for (i = 0; title[i] && title[i] != '\n' && i < 50; ) {
15+            const char *p = &title[i];
16+            unsigned int cp = xs_utf8_dec(&p);
17+            int n = p - title;
18+            if (cp == 0xfffd || n > 50)
19+                break;
20+            i = n;
21+        }
22 
23         if (title[i] != '\0') {
24             title[i] = '\0';