mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 09:10:35 +08:00
Add simple domain validation
This commit is contained in:
parent
18a8eafd04
commit
42302b0310
@ -6,6 +6,7 @@ const { cpus } = require('os');
|
|||||||
const threads = Math.max(cpus().length, 12);
|
const threads = Math.max(cpus().length, 12);
|
||||||
|
|
||||||
const rIPv4 = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
|
const rIPv4 = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
|
||||||
|
const rDomain = /^(((?!\-))(xn\-\-)?[a-z0-9\-_]{0,61}[a-z0-9]{1,1}\.)*(xn\-\-)?([a-z0-9\-]{1,61}|[a-z0-9\-]{1,30})\.[a-z]{2,}$/m
|
||||||
|
|
||||||
const Piscina = require('piscina');
|
const Piscina = require('piscina');
|
||||||
|
|
||||||
@ -59,10 +60,13 @@ async function processHosts(hostsUrl, includeAllSubDomain = false) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [, ...domains] = line.split(' ');
|
const [, ...domains] = line.split(' ');
|
||||||
|
const domain = domains.join(' ').trim();
|
||||||
|
if (rDomain.test(domain)) {
|
||||||
if (includeAllSubDomain) {
|
if (includeAllSubDomain) {
|
||||||
domainSets.add(`.${domains.join(' ')}`.trim());
|
domainSets.add(`.${domain}`);
|
||||||
} else {
|
} else {
|
||||||
domainSets.add(domains.join(' ').trim());
|
domainSets.add(domain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -136,7 +140,10 @@ async function processFilterRules(filterRulesUrl) {
|
|||||||
|| line.endsWith('^|')
|
|| line.endsWith('^|')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
whitelistDomainSets.add(`${line.replaceAll('@@||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim());
|
const domain = `${line.replaceAll('@@||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
|
||||||
|
if (rDomain.test(domain)) {
|
||||||
|
whitelistDomainSets.add(domain);
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
line.startsWith('||')
|
line.startsWith('||')
|
||||||
&& (
|
&& (
|
||||||
@ -144,14 +151,20 @@ async function processFilterRules(filterRulesUrl) {
|
|||||||
|| line.endsWith('^|')
|
|| line.endsWith('^|')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
blacklistDomainSets.add(`.${line.replaceAll('||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim());
|
const domain = `${line.replaceAll('||', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
|
||||||
|
if (rDomain.test(domain)) {
|
||||||
|
blacklistDomainSets.add(`.${domain}`);
|
||||||
|
}
|
||||||
} else if (line.startsWith('://')
|
} else if (line.startsWith('://')
|
||||||
&& (
|
&& (
|
||||||
line.endsWith('^')
|
line.endsWith('^')
|
||||||
|| line.endsWith('^|')
|
|| line.endsWith('^|')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
blacklistDomainSets.add(`${line.replaceAll('://', '').replaceAll('^|', '').replaceAll('^', '')}`.trim());
|
const domain = `${line.replaceAll('://', '').replaceAll('^|', '').replaceAll('^', '')}`.trim();
|
||||||
|
if (rDomain.test(domain)) {
|
||||||
|
blacklistDomainSets.add(domain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -350,7 +350,6 @@ xy-log.tagtic.cn
|
|||||||
.talkingdata.com
|
.talkingdata.com
|
||||||
.tango-deg.com
|
.tango-deg.com
|
||||||
.tanv.com
|
.tanv.com
|
||||||
.tanx.com
|
|
||||||
.taplytics.com
|
.taplytics.com
|
||||||
.taptica.com
|
.taptica.com
|
||||||
.testplus.cn
|
.testplus.cn
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user