Skip to content
Permalink
Branch: master
Commits on Mar 8, 2019
  1. Increase TLD size on Link Filter

    Alipoodle committed Mar 8, 2019
    ![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.
You can’t perform that action at this time.