diff options
author | default <nobody@localhost> | 2023-06-01 17:14:50 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-06-01 17:14:50 +0200 |
commit | e66b3ff8daa86753855e536a3b769f01d66a92bf (patch) | |
tree | 2d2579c2e73fd25809c8711fec7d46b2cceb5a29 | |
parent | af88b784786dc3f354ddb8e6a1a8cb2bbf4c44b4 (diff) |
Disallow empty or repeated options in msg_question().
-rw-r--r-- | activitypub.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c index dddeb20..4919a61 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1057,6 +1057,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, xs *ntid = tid(0); xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0); int max = 8; + xs_set seen; msg = xs_dict_set(msg, "type", "Question"); @@ -1068,20 +1069,30 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, xs_str *v; xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}"); - while (max-- && xs_list_iter(&p, &v)) { - xs *v2 = xs_dup(v); - xs *d = xs_dict_new(); + xs_set_init(&seen); - if (strlen(v2) > 60) { - v2[60] = '\0'; - v2 = xs_str_cat(v2, "..."); - } + while (max && xs_list_iter(&p, &v)) { + if (*v) { + xs *v2 = xs_dup(v); + xs *d = xs_dict_new(); + + if (strlen(v2) > 60) { + v2[60] = '\0'; + v2 = xs_str_cat(v2, "..."); + } + + if (xs_set_add(&seen, v2) == 1) { + d = xs_dict_append(d, "name", v2); + d = xs_dict_append(d, "replies", replies); + o = xs_list_append(o, d); - d = xs_dict_append(d, "name", v2); - d = xs_dict_append(d, "replies", replies); - o = xs_list_append(o, d); + max--; + } + } } + xs_set_free(&seen); + msg = xs_dict_append(msg, multiple ? "anyOf" : "oneOf", o); /* set the end time */ |