diff options
| author | Alexandre Oliva <oliva@gnu.org> | 2026-01-01 16:27:21 +0100 |
|---|---|---|
| committer | grunfink <grunfink@comam.es> | 2026-01-01 16:27:21 +0100 |
| commit | 89053095eb70eff4527dfc3052d517eeb07fc816 (patch) | |
| tree | cdd341292b44ab241999f608e49452de51913404 /rss.c | |
| parent | 20eba6f5192176ad0fc3c468cd4bd8dda62f15e6 (diff) | |
truncate rss title at utf8 char boundary
Advance a whole utf8 char at a time while looking for where to
truncate the title.
Diffstat (limited to 'rss.c')
| -rw-r--r-- | rss.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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'; |