Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut URLs before adding to automcomp at > #1883

Merged
merged 1 commit into from
Sep 5, 2023
Merged

Cut URLs before adding to automcomp at > #1883

merged 1 commit into from
Sep 5, 2023

Conversation

jubalh
Copy link
Member

@jubalh jubalh commented Aug 28, 2023

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.

Let's cut the string at > since they are sometimes enclosed in <>.

Fix #1877

@jubalh jubalh added this to the next milestone Aug 28, 2023
@jubalh jubalh requested a review from sjaeckel August 28, 2023 11:01
@jubalh jubalh self-assigned this Aug 28, 2023
@jubalh
Copy link
Member Author

jubalh commented Sep 4, 2023

Maybe adjusting the regex used at https://github.com/profanity-im/profanity/pull/1883/files#diff-1a7db58e738a75a1ee3630328ced5287e85e1f30168c13d6d1d680d5f7c2a830L1313 would be better. If anyone is a regex master here .. ;)

@sjaeckel
Copy link
Member

sjaeckel commented Sep 4, 2023

Maybe adjusting the regex used at https://github.com/profanity-im/profanity/pull/1883/files#diff-1a7db58e738a75a1ee3630328ced5287e85e1f30168c13d6d1d680d5f7c2a830L1313 would be better. If anyone is a regex master here .. ;)

... now we have two problems ...

$ git diff -U1
diff --git a/src/ui/window_list.c b/src/ui/window_list.c
index a00fcb43..2206c6d8 100644
--- a/src/ui/window_list.c
+++ b/src/ui/window_list.c
@@ -1312,3 +1312,3 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
 
-    regex = g_regex_new("(https?|aesgcm)://\\S+", 0, 0, NULL);
+    regex = g_regex_new("(https?|aesgcm)://[\\w\\-.~:/?#\\[\\]@!$&'()*+,;=%]+", 0, 0, NULL);
     g_regex_match(regex, message->plain, 0, &match_info);

No regex master here, https://stackoverflow.com/q/43588699 did most of the work, I only had to adapt the escaping.

@sjaeckel
Copy link
Member

sjaeckel commented Sep 4, 2023

Could you please add a comment that references the SO thread?

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 #1877
@jubalh jubalh merged commit 394c935 into master Sep 5, 2023
6 checks passed
@jubalh jubalh deleted the fix/1877-url branch September 5, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Profanity fails to properly detect URLs wrapped in <>
2 participants