mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-08 03:27:20 +00:00
yeet all trailing characters from TLDs
Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
9dce492de4
commit
abd5b15588
1 changed files with 10 additions and 1 deletions
|
@ -625,6 +625,7 @@ 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;
|
||||
|
@ -647,7 +648,15 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
|
|||
return urls;
|
||||
}
|
||||
|
||||
const hostname = matchUrl.hostname.endsWith(".") ? matchUrl.hostname.slice(0, -1) : matchUrl.hostname;
|
||||
//let hostname = matchUrl.hostname.endsWith(".") ? matchUrl.hostname.slice(0, -1) : matchUrl.hostname;
|
||||
let hostname = matchUrl.hostname.toLowerCase();
|
||||
|
||||
if (hostname.length > 3) {
|
||||
while (!hostnameTldRegex.test(hostname.at(-1)!)) {
|
||||
if (!hostname.length) break;
|
||||
hostname = hostname.slice(0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
const hostnameParts = hostname.split(".");
|
||||
const tld = hostnameParts[hostnameParts.length - 1];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue