1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Adjust regex to match URLs

First I tried with g_uri_parse() and g_uri_to_string() but then I
learned that GUri validation API is only for things that are part of a
proper URL.

Then used `g_utf8_strchr()` to cut the string at `>` since they are
sometimes enclosed in `<>`.

Thanks to @sjaeckel for providing a proper regex from
https://stackoverflow.com/questions/43588699/regex-for-matching-any-url-character

Fix https://github.com/profanity-im/profanity/issues/1877
This commit is contained in:
Michael Vetter 2023-08-28 12:58:00 +02:00
parent 8618203988
commit 9f08cd44a6

View File

@ -1310,7 +1310,8 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
GRegex* regex;
GMatchInfo* match_info;
regex = g_regex_new("(https?|aesgcm)://\\S+", 0, 0, NULL);
// https://stackoverflow.com/questions/43588699/regex-for-matching-any-url-character
regex = g_regex_new("(https?|aesgcm)://[\\w\\-.~:/?#\\[\\]@!$&'()*+,;=%]+", 0, 0, NULL);
g_regex_match(regex, message->plain, 0, &match_info);
while (g_match_info_matches(match_info)) {