commit 5aaa619
default
·
2025-01-12 13:59:28 +0000 UTC
parent 6d0b0cd
Better dangling hashtag checking.
3 files changed,
+11,
-8
M
html.c
+7,
-7
1@@ -2317,8 +2317,9 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
2
3 /* show all hashtags that has not been shown previously in the content */
4 const xs_list *tags = xs_dict_get(msg, "tag");
5- if (xs_type(tags) == XSTYPE_LIST && xs_list_len(tags)) {
6- const char *o_content = xs_dict_get_def(msg, "content", "");
7+ const char *o_content = xs_dict_get_def(msg, "content", "");
8+
9+ if (xs_is_string(o_content) && xs_is_list(tags) && xs_list_len(tags)) {
10 xs *content = xs_utf8_to_lower(o_content);
11 const xs_dict *tag;
12
13@@ -2328,16 +2329,15 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
14 xs_list_foreach(tags, tag) {
15 const char *type = xs_dict_get(tag, "type");
16
17- if (xs_type(type) == XSTYPE_STRING && strcmp(type, "Hashtag") == 0) {
18+ if (xs_is_string(type) && strcmp(type, "Hashtag") == 0) {
19 const char *o_href = xs_dict_get(tag, "href");
20+ const char *name = xs_dict_get(tag, "name");
21
22- if (xs_type(o_href) == XSTYPE_STRING) {
23+ if (xs_is_string(o_href) && xs_is_string(name)) {
24 xs *href = xs_utf8_to_lower(o_href);
25
26- if (xs_str_in(content, href) == -1) {
27+ if (xs_str_in(content, href) == -1 && xs_str_in(content, name) == -1) {
28 /* not in the content: add here */
29- const char *name = xs_dict_get(tag, "name");
30-
31 xs_html_add(add_hashtags,
32 xs_html_tag("li",
33 xs_html_tag("a",
M
xs.h
+3,
-0
1@@ -157,6 +157,9 @@ unsigned int xs_hash_func(const char *data, int size);
2 #define xs_is_true(v) (xs_type((v)) == XSTYPE_TRUE)
3 #define xs_is_false(v) (xs_type((v)) == XSTYPE_FALSE)
4 #define xs_not(v) xs_stock(xs_is_true((v)) ? XSTYPE_FALSE : XSTYPE_TRUE)
5+#define xs_is_string(v) (xs_type((v)) == XSTYPE_STRING)
6+#define xs_is_list(v) (xs_type((v)) == XSTYPE_LIST)
7+#define xs_is_dict(v) (xs_type((v)) == XSTYPE_DICT)
8
9 #define xs_list_foreach(l, v) for (int ct_##__LINE__ = 0; xs_list_next(l, &v, &ct_##__LINE__); )
10 #define xs_dict_foreach(l, k, v) for (int ct_##__LINE__ = 0; xs_dict_next(l, &k, &v, &ct_##__LINE__); )
+1,
-1
1@@ -1 +1 @@
2-/* c317231894f28c39ba45a46f493f124d12a12f3a 2025-01-12T06:56:21+01:00 */
3+/* cebb5663f26bc91b80c787525f5953b97839e0f7 2025-01-12T14:57:12+01:00 */