summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Oliva2026-01-01 16:27:21 +0100
committerGravatar grunfink2026-01-01 16:27:21 +0100
commit89053095eb70eff4527dfc3052d517eeb07fc816 (patch)
treecdd341292b44ab241999f608e49452de51913404
parentAdd boosts, likes and reacts to actor's people page (diff)
downloadsnac2-89053095eb70eff4527dfc3052d517eeb07fc816.tar.gz
snac2-89053095eb70eff4527dfc3052d517eeb07fc816.tar.xz
snac2-89053095eb70eff4527dfc3052d517eeb07fc816.zip
truncate rss title at utf8 char boundary
Advance a whole utf8 char at a time while looking for where to truncate the title.
-rw-r--r--RELEASE_NOTES.md2
-rw-r--r--rss.c10
2 files changed, 11 insertions, 1 deletions
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 @@
2 2
3## UNRELEASED 3## UNRELEASED
4 4
5Truncate RSS titles at UTF-8 character boundaries (contributed by lxo).
6
5Link contacts to single-user people pages. Also, user's posts are shown (contributed by lxo). 7Link contacts to single-user people pages. Also, user's posts are shown (contributed by lxo).
6 8
7Added emoji reactions (contributed by violette). 9Added 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 @@
10#include "xs_openssl.h" 10#include "xs_openssl.h"
11#include "xs_json.h" 11#include "xs_json.h"
12#include "xs_http.h" 12#include "xs_http.h"
13#include "xs_unicode.h"
13 14
14#include "snac.h" 15#include "snac.h"
15 16
@@ -74,7 +75,14 @@ xs_str *rss_from_timeline(snac *user, const xs_list *timeline,
74 title = xs_regex_replace_i(title, "&[^;]+;", " "); 75 title = xs_regex_replace_i(title, "&[^;]+;", " ");
75 int i; 76 int i;
76 77
77 for (i = 0; title[i] && title[i] != '\n' && i < 50; i++); 78 for (i = 0; title[i] && title[i] != '\n' && i < 50; ) {
79 const char *p = &title[i];
80 unsigned int cp = xs_utf8_dec(&p);
81 int n = p - title;
82 if (cp == 0xfffd || n > 50)
83 break;
84 i = n;
85 }
78 86
79 if (title[i] != '\0') { 87 if (title[i] != '\0') {
80 title[i] = '\0'; 88 title[i] = '\0';