瀏覽代碼

Fix: hosts parsing

SukkaW 2 年之前
父節點
當前提交
9e09222472
共有 3 個文件被更改,包括 17 次插入17 次删除
  1. 9 11
      Build/lib/parse-filter.ts
  2. 6 6
      Build/lib/process-line.ts
  3. 2 0
      Build/lib/reject-data-source.ts

+ 9 - 11
Build/lib/parse-filter.ts

@@ -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);
       }
     }
 

+ 6 - 6
Build/lib/process-line.ts

@@ -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;
 };
 

+ 2 - 0
Build/lib/reject-data-source.ts

@@ -133,6 +133,8 @@ export const ADGUARD_FILTERS = [
 
 export const PREDEFINED_WHITELIST = [
   'localhost',
+  'local',
+  'localhost.localdomain',
   'broadcasthost',
   'ip6-loopback',
   'ip6-localnet',