From 7c946949d6fca80a24deaf14cd613c055a597881 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Fri, 29 Dec 2023 11:43:36 +0000 Subject: [PATCH] automod match_link fixes (#432) * remove trailing dot from FQDN for TLD check Signed-off-by: GitHub * yeet all trailing characters from TLDs Signed-off-by: GitHub * oops Signed-off-by: GitHub * move dumb loop to regex replace Signed-off-by: GitHub --------- Signed-off-by: GitHub Co-authored-by: Almeida --- backend/src/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 1bb4d6ce..c6c705db 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -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);