mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 02:57:20 +00:00
move dumb loop to regex replace
Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
089d7a7b65
commit
d4c591b8ee
1 changed files with 1 additions and 5 deletions
|
@ -625,7 +625,6 @@ const plainLinkRegex = /((?!https?:\/\/)\S)+\.\S+/; // anything.anything, withou
|
||||||
// Both of the above, with precedence on the first one
|
// Both of the above, with precedence on the first one
|
||||||
const urlRegex = new RegExp(`(${realLinkRegex.source}|${plainLinkRegex.source})`, "g");
|
const urlRegex = new RegExp(`(${realLinkRegex.source}|${plainLinkRegex.source})`, "g");
|
||||||
const protocolRegex = /^[a-z]+:\/\//;
|
const protocolRegex = /^[a-z]+:\/\//;
|
||||||
const hostnameTldRegex = /^[a-z]$/;
|
|
||||||
|
|
||||||
interface MatchedURL extends URL {
|
interface MatchedURL extends URL {
|
||||||
input: string;
|
input: string;
|
||||||
|
@ -651,10 +650,7 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
|
||||||
let hostname = matchUrl.hostname.toLowerCase();
|
let hostname = matchUrl.hostname.toLowerCase();
|
||||||
|
|
||||||
if (hostname.length > 3) {
|
if (hostname.length > 3) {
|
||||||
while (!hostnameTldRegex.test(hostname.at(-1)!)) {
|
hostname = hostname.replace(/[^a-z]+$/, "");
|
||||||
if (!hostname.length) break;
|
|
||||||
hostname = hostname.slice(0, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const hostnameParts = hostname.split(".");
|
const hostnameParts = hostname.split(".");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue