Skip to content

Commit

Permalink
automod match_link fixes (#432)
Browse files Browse the repository at this point in the history
* remove trailing dot from FQDN for TLD check

Signed-off-by: GitHub <[email protected]>

* yeet all trailing characters from TLDs

Signed-off-by: GitHub <[email protected]>

* oops

Signed-off-by: GitHub <[email protected]>

* move dumb loop to regex replace

Signed-off-by: GitHub <[email protected]>

---------

Signed-off-by: GitHub <[email protected]>
Co-authored-by: Almeida <[email protected]>
  • Loading branch information
metal0 and almeidx authored Dec 29, 2023
1 parent d09e056 commit 7c94694
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,13 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
return urls;
}

const hostnameParts = matchUrl.hostname.split(".");
let hostname = matchUrl.hostname.toLowerCase();

if (hostname.length > 3) {
hostname = hostname.replace(/[^a-z]+$/, "");
}

const hostnameParts = hostname.split(".");
const tld = hostnameParts[hostnameParts.length - 1];
if (tlds.includes(tld)) {
urls.push(matchUrl);
Expand Down

0 comments on commit 7c94694

Please sign in to comment.