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

Evil Tracking Remover Is Very Hungry (Issue when using <> to silence embeds) #116

Open
fly-san opened this issue Feb 12, 2024 · 0 comments

Comments

@fly-san
Copy link
Contributor

fly-san commented Feb 12, 2024

The bot currently uses the following regex (https?://\S+) to find links, this has a very annoying edge case, which I will break down now:

  1. Discord allows users to wrap links with < and > to hide embeds automatically (such as <https://example.com>)
  2. If a link is wrapped with <>, discord will correctly recognize where the URL ends, furthermore, it stops highlighting the link in blue, which allows users to type normal messages after the link without using space/whitespace for separation>
    grafik
  3. Within the bot, because the regex terminates with \S+ we only ever stop matching the URL after whitespace is found.
  4. If the bot detects an evil tracking parameter and the message author has not included whitespace after the link, their proceeding message will always have its first word considered part of the evil parameter and trimmed.
    grafik
    (In the example the word "haha" was trimmed)
  5. A less relevant side-effect which can also be seen in the example is that this will also cause the image to be embedded despite the author having deliberately wrapped it with <> to avoid an embed.

Proposal:

Change the existing URL regex to a new format (see below)

Old:

urls = re.findall(r'(https?://\S+)', message.content)

Proposed:
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) taken from stackoverflow seems accurate enough I guess.

Other options are available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant