mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-03 12:31:54 +08:00
Fix: domain deduper
This commit is contained in:
@@ -6,22 +6,19 @@ export function domainDeduper(inputDomains: string[], toArray = true): string[]
|
|||||||
const trie = createTrie(inputDomains);
|
const trie = createTrie(inputDomains);
|
||||||
const sets = new Set(inputDomains);
|
const sets = new Set(inputDomains);
|
||||||
|
|
||||||
for (let i = 0, len = inputDomains.length; i < len; i++) {
|
for (let i = 0, len1 = inputDomains.length; i < len1; i++) {
|
||||||
const d = inputDomains[i];
|
const d = inputDomains[i];
|
||||||
if (d[0] !== '.') {
|
if (d[0] !== '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const found = trie.find(d, true);
|
const found = trie.find(d, false);
|
||||||
for (let j = 0, len = found.length; j < len; j++) {
|
|
||||||
|
for (let j = 0, len2 = found.length; j < len2; j++) {
|
||||||
sets.delete(found[j]);
|
sets.delete(found[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const a: string = d.slice(1);
|
sets.delete(d.slice(1));
|
||||||
|
|
||||||
if (sets.has(a)) {
|
|
||||||
sets.delete(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toArray) {
|
if (toArray) {
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ export const normalizeDomain = (domain: string) => {
|
|||||||
|
|
||||||
let h = parsed.hostname;
|
let h = parsed.hostname;
|
||||||
|
|
||||||
let sliceStart = 0;
|
let sliceStart: number | undefined;
|
||||||
let sliceEnd = h.length;
|
let sliceEnd: number | undefined;
|
||||||
|
|
||||||
if (h[0] === '.') sliceStart = 1;
|
if (h[0] === '.') sliceStart = 1;
|
||||||
if (h.endsWith('.')) sliceEnd = -1;
|
if (h.endsWith('.')) sliceEnd = -1;
|
||||||
|
|
||||||
if (sliceStart !== 0 || sliceEnd !== h.length) {
|
if (sliceStart !== undefined || sliceEnd !== undefined) {
|
||||||
h = h.slice(sliceStart, sliceEnd);
|
h = h.slice(sliceStart, sliceEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user