mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Fix: hosts parsing
This commit is contained in:
parent
a0a772d2e1
commit
9e09222472
@ -10,7 +10,7 @@ import { isProbablyIpv4 } from './is-fast-ip';
|
||||
import { traceAsync } from './trace-runner';
|
||||
import picocolors from 'picocolors';
|
||||
|
||||
const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
|
||||
const DEBUG_DOMAIN_TO_FIND: string | null = 'video'; // example.com | null
|
||||
let foundDebugDomain = false;
|
||||
|
||||
const warnOnceUrl = new Set<string>();
|
||||
@ -67,22 +67,20 @@ export async function processHosts(hostsUrl: string, includeAllSubDomain = false
|
||||
continue;
|
||||
}
|
||||
|
||||
const [, ...domains] = line.split(' ');
|
||||
const _domain = domains.join(' ').trim();
|
||||
const [, domain] = line.split(/\s/);
|
||||
if (!domain) {
|
||||
continue;
|
||||
}
|
||||
const _domain = domain.trim();
|
||||
|
||||
if (DEBUG_DOMAIN_TO_FIND && _domain.includes(DEBUG_DOMAIN_TO_FIND)) {
|
||||
warnOnce(hostsUrl, false, DEBUG_DOMAIN_TO_FIND);
|
||||
foundDebugDomain = true;
|
||||
}
|
||||
|
||||
const domain = skipDomainCheck ? _domain : normalizeDomain(_domain);
|
||||
|
||||
if (domain) {
|
||||
if (includeAllSubDomain) {
|
||||
domainSets.add(`.${domain}`);
|
||||
} else {
|
||||
domainSets.add(domain);
|
||||
}
|
||||
const domainToAdd = skipDomainCheck ? _domain : normalizeDomain(_domain);
|
||||
if (domainToAdd) {
|
||||
domainSets.add(includeAllSubDomain ? `.${domainToAdd}` : domainToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,12 @@ export const processLine = (line: string): string | null => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const line_0: string = line[0];
|
||||
const trimmed: string = line.trim();
|
||||
if (trimmed === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const line_0: string = trimmed[0];
|
||||
|
||||
if (
|
||||
line_0 === '#'
|
||||
@ -15,11 +20,6 @@ export const processLine = (line: string): string | null => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const trimmed: string = line.trim();
|
||||
if (trimmed === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
|
||||
@ -133,6 +133,8 @@ export const ADGUARD_FILTERS = [
|
||||
|
||||
export const PREDEFINED_WHITELIST = [
|
||||
'localhost',
|
||||
'local',
|
||||
'localhost.localdomain',
|
||||
'broadcasthost',
|
||||
'ip6-loopback',
|
||||
'ip6-localnet',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user