mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Parse reject with IP support [skip ci]
This commit is contained in:
@@ -10,12 +10,9 @@ export type TldTsParsed = ReturnType<typeof tldts.parse>;
|
||||
/**
|
||||
* Skipped the input non-empty check, the `domain` should not be empty.
|
||||
*/
|
||||
export function fastNormalizeDomainWithoutWww(domain: string, parsed: TldTsParsed | null = null) {
|
||||
export function fastNormalizeDomainWithoutWwwNoIP(domain: string, parsed: TldTsParsed | null = null) {
|
||||
// We don't want tldts to call its own "extractHostname" on ip, bail out ip first.
|
||||
// Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false.
|
||||
if (isProbablyIpv4(domain) || isProbablyIpv6(domain)) {
|
||||
return null;
|
||||
}
|
||||
// This function won't run with IP, we can safely set normalizeTldtsOpt.detectIp to false.
|
||||
|
||||
parsed ??= tldts.parse(domain, normalizeTldtsOpt);
|
||||
// Private invalid domain (things like .tor, .dn42, etc)
|
||||
@@ -33,6 +30,19 @@ export function fastNormalizeDomainWithoutWww(domain: string, parsed: TldTsParse
|
||||
return parsed.hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skipped the input non-empty check, the `domain` should not be empty.
|
||||
*/
|
||||
export function fastNormalizeDomainWithoutWww(domain: string, parsed: TldTsParsed | null = null) {
|
||||
// We don't want tldts to call its own "extractHostname" on ip, bail out ip first.
|
||||
// Now ip has been bailed out, we can safely set normalizeTldtsOpt.detectIp to false.
|
||||
if (isProbablyIpv4(domain) || isProbablyIpv6(domain)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fastNormalizeDomainWithoutWwwNoIP(domain, parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skipped the input non-empty check, the `domain` should not be empty.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user