Chore: many changes

- Move `parse-filter.test.ts`
- Add more kwfilter bail out to parse filter
This commit is contained in:
SukkaW 2025-02-23 22:45:48 +08:00
parent 3952e27d64
commit be063f09a7
3 changed files with 15 additions and 6 deletions

View File

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

View File

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

View File

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