diff --git a/format.c b/format.c
index 482edce..4491ae0 100644
--- a/format.c
+++ b/format.c
@@ -238,3 +238,19 @@ xs_str *sanitize(const char *content)
return s;
}
+
+
+xs_str *encode_html(const char *str)
+/* escapes html characters */
+{
+ xs_str *encoded = xs_replace(str, "&", "&");
+ encoded = xs_replace_i(encoded, "<", "<");
+ encoded = xs_replace_i(encoded, ">", ">");
+ encoded = xs_replace_i(encoded, "\"", """);
+ encoded = xs_replace_i(encoded, "'", "'");
+
+ /* Restore only
. Probably safe. Let's hope nothing goes wrong with this. */
+ encoded = xs_replace_i(encoded, "<br>", "
");
+
+ return encoded;
+}
diff --git a/html.c b/html.c
index 4541571..a88961e 100644
--- a/html.c
+++ b/html.c
@@ -52,7 +52,7 @@ xs_str *actor_name(xs_dict *actor)
}
}
- name = xs_dup(v);
+ name = encode_html(v);
/* replace the :shortnames: */
if (!xs_is_null(p = xs_dict_get(actor, "tag"))) {
@@ -105,7 +105,7 @@ xs_str *html_actor_icon(xs_str *os, char *actor,
{
xs *s1 = xs_fmt("%s",
- xs_dict_get(actor, "id"), xs_encode_html(name));
+ xs_dict_get(actor, "id"), name);
s = xs_str_cat(s, s1);
}
@@ -137,9 +137,11 @@ xs_str *html_actor_icon(xs_str *os, char *actor,
date_title = xs_str_cat(date_title, udate);
}
+ xs *edt = encode_html(date_title);
+ xs *edl = encode_html(date_label);
xs *s1 = xs_fmt(
"\n\n",
- xs_encode_html(date_title), xs_encode_html(date_label));
+ edt, edl);
s = xs_str_cat(s, s1);
}
@@ -162,9 +164,10 @@ xs_str *html_actor_icon(xs_str *os, char *actor,
xs *domain = xs_split(id, "/");
xs *user = xs_fmt("@%s@%s", username, xs_list_get(domain, 2));
+ xs *u1 = encode_html(user);
s1 = xs_fmt(
"
%s",
- xs_dict_get(actor, "id"), xs_encode_html(user));
+ xs_dict_get(actor, "id"), u1);
s = xs_str_cat(s, s1);
}
@@ -244,10 +247,10 @@ d_char *html_user_header(snac *snac, d_char *s, int local)
}
{
- xs *s1 = xs_fmt("
%s
\n" "@%s@%s
\n"; - xs *s1 = xs_fmt(_tmpl, - xs_encode_html(xs_dict_get(snac->config, "name")), - xs_encode_html(xs_dict_get(snac->config, "uid")), xs_encode_html(xs_dict_get(srv_config, "host")) - ); + xs *es1 = encode_html(xs_dict_get(snac->config, "name")); + xs *es2 = encode_html(xs_dict_get(snac->config, "uid")); + xs *es3 = encode_html(xs_dict_get(srv_config, "host")); + + xs *s1 = xs_fmt(_tmpl, es1, es2, es3); s = xs_str_cat(s, s1); if (local) { - xs *bio1 = not_really_markdown(xs_encode_html(xs_dict_get(snac->config, "bio")), NULL); + xs *es1 = encode_html(xs_dict_get(snac->config, "bio")); + xs *bio1 = not_really_markdown(es1, NULL); xs *tags = xs_list_new(); - xs *bio2 = xs_encode_html(process_tags(snac, bio1, &tags)); + xs *bio2 = encode_html(process_tags(snac, bio1, &tags)); xs *s1 = xs_fmt("%s %s
", L("Closes in"), xs_encode_html(p)); + xs *es1 = encode_html(p); + xs *s1 = xs_fmt("%s %s
", L("Closes in"), es1); c = xs_str_cat(c, s1); } } @@ -1135,8 +1147,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, continue; if (xs_startswith(t, "image/")) { - char *url = xs_dict_get(v, "url"); - char *name = xs_encode_html(xs_dict_get(v, "name")); + char *url = xs_dict_get(v, "url"); + xs *name = encode_html(xs_dict_get(v, "name")); if (url != NULL) { if (xs_is_null(name)) @@ -1150,8 +1162,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, } else if (xs_startswith(t, "video/")) { - char *url = xs_dict_get(v, "url"); - char *name = xs_encode_html(xs_dict_get(v, "name")); + char *url = xs_dict_get(v, "url"); + xs *name = encode_html(xs_dict_get(v, "name")); if (url != NULL) { xs *s1 = xs_fmt("\n", url, url, name ? name : "No description."); @@ -1161,8 +1173,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, } else if (xs_startswith(t, "audio/")) { - char *url = xs_dict_get(v, "url"); - char *name = xs_encode_html(xs_dict_get(v, "name")); + char *url = xs_dict_get(v, "url"); + xs *name = encode_html(xs_dict_get(v, "name")); if (url != NULL) { xs *s1 = xs_fmt("\n", url, url, name ? name : "No description."); @@ -1171,8 +1183,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, } } else { - char *url = xs_dict_get(v, "url"); - char *name = xs_encode_html(xs_dict_get(v, "name")); + char *url = xs_dict_get(v, "url"); + xs *name = encode_html(xs_dict_get(v, "name")); if (url != NULL) { xs *s1 = xs_fmt("Attachment: %s", url, name ? name : "No description"); @@ -1349,7 +1361,8 @@ xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int d_char *html_people_list(snac *snac, d_char *os, d_char *list, const char *header, const char *t) { xs *s = xs_str_new(NULL); - xs *h = xs_fmt("")) s = xs_str_cat(s, sc); else { - xs *s1 = xs_fmt("
%s
", xs_encode_html(sc)); + xs *es1 = encode_html(sc); + xs *s1 = xs_fmt("%s
", es1); s = xs_str_cat(s, s1); } @@ -1549,9 +1563,10 @@ xs_str *html_notifications(snac *snac) if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0) label = L("Unfollow"); + xs *es1 = encode_html(label); xs *s1 = xs_fmt("%s by %s:
\n", - xs_encode_html(label), actor_id, xs_encode_html(a_name)); + es1, actor_id, a_name); s = xs_str_cat(s, s1); if (strcmp(type, "Follow") == 0 || strcmp(utype, "Follow") == 0) { @@ -1776,7 +1791,10 @@ int html_get_handler(const xs_dict *req, const char *q_path, xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); char *p, *v; - + xs *es1 = encode_html(xs_dict_get(snac.config, "name")); + xs *es2 = encode_html(snac.uid); + xs *es3 = encode_html(xs_dict_get(srv_config, "host")); + xs *es4 = encode_html(bio); rss = xs_fmt( "\n" "