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

Increase TLD size on Link Filter #292

Merged
merged 1 commit into from Mar 8, 2019

Conversation

Projects
None yet
2 participants
@Alipoodle
Copy link
Contributor

Alipoodle commented Mar 8, 2019

image
Blue highlight = triggered the regex
Page for above

The existing Regex for the link is good, however there are some TLDs that will be completely ignored by this expression allowing users to post links with long enough TLDs.
The average TLD is around 6 (likely for why this regex used it) but it you want to go full overkill, some TLDs you can buy are around 12 chars long, with 24 being the max (Although this is Japanese characters or something).
The image shows a few examples of some of the URLs I found with download, computer and technology being more likely to be used on a server.

Little test script.

var URL = "http://www.alphaconsole.download"
let matches = url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig));
// Currently using the default 6, but edit with 12 to show that it won't popup with the delete message. 
let filtered = matches ? matches.filter(m => {
	if (m.endsWith("discord.gg/alphaconsole")  || m.includes("imgur.com") || m.includes("reddit.com") || m.includes("gyazo.com") ||
 m.includes("prntscr.com"))
		return false
	else
		return true
}) : null;

if (filtered && filtered[0]) {
	console.log("MESSAGE DELETED");
}

Change the URL at the top / the regex with the higher TLD count to see it work

Increase TLD size on Link Filter
![image](https://puu.sh/CWYLb/f19e69cba4.png)

The existing Regex for the link is good, however there are some TLDs that will be completely ignored by this expression allowing users to post links with long enough TLDs.
The average TLD is around 6 (likely as around 95% of URLs are this length as it's short) but it you want to go full overkill, some TLDs you can buy are around 12 chars long, with 24 being the max (Although this is Japanese characters or something).
The image shows a few examples of some of the URLs I found with `download`, `computer` and `technology` being more likely to be used on a server. 

Little test script.
```
var URL = "http://www.alphaconsole.download"
let matches = url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig));
// Currently using the default 6, but edit with 12 to show that it won't popup with the delete message. 
let filtered = matches ? matches.filter(m => {
	if (m.endsWith("discord.gg/alphaconsole")  || m.includes("imgur.com") || m.includes("reddit.com") || m.includes("gyazo.com") ||
 m.includes("prntscr.com"))
		return false
	else
		return true
}) : null;

if (filtered && filtered[0]) {
	console.log("MESSAGE DELETED");
}
```
Notably you can also change the `if (discord || includes("x") || includes("y") || includes("z")` to not be an if to return, although this is generally better for readability.
@ThePjpollie

This comment has been minimized.

Copy link
Collaborator

ThePjpollie commented Mar 8, 2019

Good catch! Thanks for updating that.
Next time, if you don't mind pull request to dev branch. Need to update the readme for it, I'm aware.

@ThePjpollie ThePjpollie merged commit 1380921 into AlphaConsole:master Mar 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.