Fix mentions with one @ sign

In a mention like the following, the old code had a problem: It would
split the name by '@' and get a list of two elements. Since this is
less than three, it would then try to get the domain name from the
href ("social.alexschroeder.ch") and concatenate it with the name,
resulting in "alex@social.alexschroeder.ch@social.alexschroeder.ch".
The reason was that the code expects an initial "@". In that case,
splitting "@alex@social.alexschroeder.ch" would result in three
elements, and no domain name guessing would happen. If, on the other
hand, the name was "@foo" then finding the domain name in the URL and
appending it so that you get @foo@domain.name is the correct solution.

    "tag": [
        {
            "type": "Mention",
            "href": "https://social.alexschroeder.ch/alex",
            "name": "alex@social.alexschroeder.ch"
        }
    ],

The fix consists in prepending an "@" if the name does not start with
"@" and leaving the rest of the code unchanged.
This commit is contained in:
Alex Schroeder 2022-12-07 21:55:39 +01:00
parent df1b1510b7
commit 4c996c7622

1
html.c
View file

@ -367,6 +367,7 @@ d_char *build_mentions(snac *snac, char *msg)
if (type && strcmp(type, "Mention") == 0 &&
href && strcmp(href, snac->actor) != 0 && name) {
if (name[0] != '@') name = xs_str_cat(xs_str_new("@"), name);
xs *l = xs_split(name, "@");
/* is it a name without a host? */