浏览代码

Chore: many changes

- Move `parse-filter.test.ts`
- Add more kwfilter bail out to parse filter
SukkaW 1 年之前
父节点
当前提交
be063f09a7
共有 3 个文件被更改,包括 15 次插入6 次删除
  1. 1 1
      Build/lib/fetch-assets.ts
  2. 12 3
      Build/lib/parse-filter/filters.ts
  3. 2 2
      Build/lib/parse-filter/parse-filter.test.ts

+ 1 - 1
Build/lib/fetch-assets.ts

@@ -32,7 +32,7 @@ export async function fetchAssets(url: string, fallbackUrls: null | undefined |
     }
     const res = await $$fetch(url, { signal: controller.signal, ...defaultRequestInit });
 
-    let stream = nullthrow(res.body).pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream());
+    let stream = nullthrow(res.body, url + ' has an empty body').pipeThrough(new TextDecoderStream()).pipeThrough(new TextLineStream());
     if (processLine) {
       stream = stream.pipeThrough(new ProcessLineStream());
     }

+ 12 - 3
Build/lib/parse-filter/filters.ts

@@ -129,7 +129,11 @@ const kwfilter = createKeywordFilter([
   '~',
   // special modifier
   '$popup',
+  '$denlyallow',
   '$removeparam',
+  '$uritransform',
+  '$urlskip',
+  '$replace',
   '$redirect',
   '$popunder',
   '$cname',
@@ -140,6 +144,12 @@ const kwfilter = createKeywordFilter([
   '$csp',
   '$replace',
   '$urlskip',
+  '$elemhide',
+  '$generichide',
+  '$genericblock',
+  '$header',
+  '$permissions',
+  '$ping',
   // some bad syntax
   '^popup'
 ]);
@@ -150,6 +160,8 @@ export function parse($line: string, result: [string, ParseType], includeThirdPa
     !$line.includes('.') // rule with out dot can not be a domain
     // includes
     || kwfilter($line)
+    // note that this can only excludes $redirect but not $4-,redirect, so we still need to parse it
+    // this is only an early bail out
   ) {
     result[1] = ParseType.Null;
     return result;
@@ -174,9 +186,6 @@ export function parse($line: string, result: [string, ParseType], includeThirdPa
     || lastCharCode === 46 // 46 `.`, line.endsWith('.')
     || lastCharCode === 45 // 45 `-`, line.endsWith('-')
     || lastCharCode === 95 // 95 `_`, line.endsWith('_')
-    // || line.includes('$popup')
-    // || line.includes('$removeparam')
-    // || line.includes('$popunder')
   ) {
     result[1] = ParseType.Null;
     return result;

+ 2 - 2
Build/lib/parse-filter.test.ts → Build/lib/parse-filter/parse-filter.test.ts

@@ -1,7 +1,7 @@
 import { describe, it } from 'mocha';
 
-import { parse } from './parse-filter/filters';
-import type { ParseType } from './parse-filter/filters';
+import { parse } from './filters';
+import type { ParseType } from './filters';
 
 describe('parse', () => {
   const MUTABLE_PARSE_LINE_RESULT: [string, ParseType] = ['', 1000];