mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 01:30:37 +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 { traceAsync } from './trace-runner';
|
||||||
import picocolors from 'picocolors';
|
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;
|
let foundDebugDomain = false;
|
||||||
|
|
||||||
const warnOnceUrl = new Set<string>();
|
const warnOnceUrl = new Set<string>();
|
||||||
@ -67,22 +67,20 @@ export async function processHosts(hostsUrl: string, includeAllSubDomain = false
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [, ...domains] = line.split(' ');
|
const [, domain] = line.split(/\s/);
|
||||||
const _domain = domains.join(' ').trim();
|
if (!domain) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const _domain = domain.trim();
|
||||||
|
|
||||||
if (DEBUG_DOMAIN_TO_FIND && _domain.includes(DEBUG_DOMAIN_TO_FIND)) {
|
if (DEBUG_DOMAIN_TO_FIND && _domain.includes(DEBUG_DOMAIN_TO_FIND)) {
|
||||||
warnOnce(hostsUrl, false, DEBUG_DOMAIN_TO_FIND);
|
warnOnce(hostsUrl, false, DEBUG_DOMAIN_TO_FIND);
|
||||||
foundDebugDomain = true;
|
foundDebugDomain = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = skipDomainCheck ? _domain : normalizeDomain(_domain);
|
const domainToAdd = skipDomainCheck ? _domain : normalizeDomain(_domain);
|
||||||
|
if (domainToAdd) {
|
||||||
if (domain) {
|
domainSets.add(includeAllSubDomain ? `.${domainToAdd}` : domainToAdd);
|
||||||
if (includeAllSubDomain) {
|
|
||||||
domainSets.add(`.${domain}`);
|
|
||||||
} else {
|
|
||||||
domainSets.add(domain);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,12 @@ export const processLine = (line: string): string | null => {
|
|||||||
return 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 (
|
if (
|
||||||
line_0 === '#'
|
line_0 === '#'
|
||||||
@ -15,11 +20,6 @@ export const processLine = (line: string): string | null => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const trimmed: string = line.trim();
|
|
||||||
if (trimmed === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return trimmed;
|
return trimmed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -133,6 +133,8 @@ export const ADGUARD_FILTERS = [
|
|||||||
|
|
||||||
export const PREDEFINED_WHITELIST = [
|
export const PREDEFINED_WHITELIST = [
|
||||||
'localhost',
|
'localhost',
|
||||||
|
'local',
|
||||||
|
'localhost.localdomain',
|
||||||
'broadcasthost',
|
'broadcasthost',
|
||||||
'ip6-loopback',
|
'ip6-loopback',
|
||||||
'ip6-localnet',
|
'ip6-localnet',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user