From be063f09a77d9a77348692705374af65f2fee8e7 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 23 Feb 2025 22:45:48 +0800 Subject: [PATCH] Chore: many changes - Move `parse-filter.test.ts` - Add more kwfilter bail out to parse filter --- Build/lib/fetch-assets.ts | 2 +- Build/lib/parse-filter/filters.ts | 15 ++++++++++++--- Build/lib/{ => parse-filter}/parse-filter.test.ts | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) rename Build/lib/{ => parse-filter}/parse-filter.test.ts (72%) diff --git a/Build/lib/fetch-assets.ts b/Build/lib/fetch-assets.ts index bd12b5f6..61c25654 100644 --- a/Build/lib/fetch-assets.ts +++ b/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()); } diff --git a/Build/lib/parse-filter/filters.ts b/Build/lib/parse-filter/filters.ts index cfbd4f18..4e5a9427 100644 --- a/Build/lib/parse-filter/filters.ts +++ b/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; diff --git a/Build/lib/parse-filter.test.ts b/Build/lib/parse-filter/parse-filter.test.ts similarity index 72% rename from Build/lib/parse-filter.test.ts rename to Build/lib/parse-filter/parse-filter.test.ts index e112bd0b..bbfdab42 100644 --- a/Build/lib/parse-filter.test.ts +++ b/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];