commit 7e273a7
Yonle
·
2023-07-18 16:08:09 +0000 UTC
parent d3e0f7a
html.c: RSS: fix. Feed title, and description is not properly rendered. So here goes a fix that instead of using encode_html TWICE, We use sanitize() for feed description instead. Signed-off-by: Yonle <yonle@lecturify.net>
1 files changed,
+9,
-7
M
html.c
M
html.c
+9,
-7
1@@ -1899,23 +1899,25 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2 if (!xs_startswith(id, snac.actor))
3 continue;
4
5- xs *es1 = sanitize(xs_dict_get(msg, "content"));
6- xs *content = encode_html(es1);
7+ xs *content = sanitize(xs_dict_get(msg, "content"));
8+
9+ // We SHOULD only use sanitized one for description.
10+ // So, only encode for feed title, while the description just keep it sanitized as is.
11+ xs *es_title_enc = encode_html(xs_dict_get(msg, "content"));
12+ xs *es_title = xs_replace(es_title_enc, "<br>", "\n");
13 xs *title = xs_str_new(NULL);
14 int i;
15
16- for (i = 0; content[i] && content[i] != '<' && content[i] != '&' && i < 40; i++)
17- title = xs_append_m(title, &content[i], 1);
18+ for (i = 0; es_title[i] && es_title[i] != '\n' && i < 50; i++)
19+ title = xs_append_m(title, &es_title[i], 1);
20
21- xs *es11 = encode_html(title);
22- xs *es12 = encode_html(content);
23 xs *s = xs_fmt(
24 "<item>\n"
25 "<title>%s...</title>\n"
26 "<link>%s</link>\n"
27 "<description>%s</description>\n"
28 "</item>\n",
29- es11, id, es12
30+ title, id, content
31 );
32
33 rss = xs_str_cat(rss, s);