From 89ae47c85bd5d93a01b795e221c4b5507293aa36 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Fri, 29 Dec 2023 03:30:40 +0000 Subject: [PATCH] move dumb loop to regex replace Signed-off-by: GitHub --- backend/src/utils.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 7b5460601..c6c705db6 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -625,7 +625,6 @@ const plainLinkRegex = /((?!https?:\/\/)\S)+\.\S+/; // anything.anything, withou // Both of the above, with precedence on the first one const urlRegex = new RegExp(`(${realLinkRegex.source}|${plainLinkRegex.source})`, "g"); const protocolRegex = /^[a-z]+:\/\//; -const hostnameTldRegex = /^[a-z]$/; interface MatchedURL extends URL { input: string; @@ -651,10 +650,7 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] { let hostname = matchUrl.hostname.toLowerCase(); if (hostname.length > 3) { - while (!hostnameTldRegex.test(hostname.at(-1)!)) { - if (!hostname.length) break; - hostname = hostname.slice(0, -1); - } + hostname = hostname.replace(/[^a-z]+$/, ""); } const hostnameParts = hostname.split(".");