mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-14 18:20:35 +08:00
Chore: many changes
- Move `parse-filter.test.ts` - Add more kwfilter bail out to parse filter
This commit is contained in:
parent
3952e27d64
commit
be063f09a7
@ -32,7 +32,7 @@ export async function fetchAssets(url: string, fallbackUrls: null | undefined |
|
|||||||
}
|
}
|
||||||
const res = await $$fetch(url, { signal: controller.signal, ...defaultRequestInit });
|
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) {
|
if (processLine) {
|
||||||
stream = stream.pipeThrough(new ProcessLineStream());
|
stream = stream.pipeThrough(new ProcessLineStream());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,11 @@ const kwfilter = createKeywordFilter([
|
|||||||
'~',
|
'~',
|
||||||
// special modifier
|
// special modifier
|
||||||
'$popup',
|
'$popup',
|
||||||
|
'$denlyallow',
|
||||||
'$removeparam',
|
'$removeparam',
|
||||||
|
'$uritransform',
|
||||||
|
'$urlskip',
|
||||||
|
'$replace',
|
||||||
'$redirect',
|
'$redirect',
|
||||||
'$popunder',
|
'$popunder',
|
||||||
'$cname',
|
'$cname',
|
||||||
@ -140,6 +144,12 @@ const kwfilter = createKeywordFilter([
|
|||||||
'$csp',
|
'$csp',
|
||||||
'$replace',
|
'$replace',
|
||||||
'$urlskip',
|
'$urlskip',
|
||||||
|
'$elemhide',
|
||||||
|
'$generichide',
|
||||||
|
'$genericblock',
|
||||||
|
'$header',
|
||||||
|
'$permissions',
|
||||||
|
'$ping',
|
||||||
// some bad syntax
|
// some bad syntax
|
||||||
'^popup'
|
'^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
|
!$line.includes('.') // rule with out dot can not be a domain
|
||||||
// includes
|
// includes
|
||||||
|| kwfilter($line)
|
|| 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;
|
result[1] = ParseType.Null;
|
||||||
return result;
|
return result;
|
||||||
@ -174,9 +186,6 @@ export function parse($line: string, result: [string, ParseType], includeThirdPa
|
|||||||
|| lastCharCode === 46 // 46 `.`, line.endsWith('.')
|
|| lastCharCode === 46 // 46 `.`, line.endsWith('.')
|
||||||
|| lastCharCode === 45 // 45 `-`, line.endsWith('-')
|
|| lastCharCode === 45 // 45 `-`, line.endsWith('-')
|
||||||
|| lastCharCode === 95 // 95 `_`, line.endsWith('_')
|
|| lastCharCode === 95 // 95 `_`, line.endsWith('_')
|
||||||
// || line.includes('$popup')
|
|
||||||
// || line.includes('$removeparam')
|
|
||||||
// || line.includes('$popunder')
|
|
||||||
) {
|
) {
|
||||||
result[1] = ParseType.Null;
|
result[1] = ParseType.Null;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { describe, it } from 'mocha';
|
import { describe, it } from 'mocha';
|
||||||
|
|
||||||
import { parse } from './parse-filter/filters';
|
import { parse } from './filters';
|
||||||
import type { ParseType } from './parse-filter/filters';
|
import type { ParseType } from './filters';
|
||||||
|
|
||||||
describe('parse', () => {
|
describe('parse', () => {
|
||||||
const MUTABLE_PARSE_LINE_RESULT: [string, ParseType] = ['', 1000];
|
const MUTABLE_PARSE_LINE_RESULT: [string, ParseType] = ['', 1000];
|
||||||
Loading…
x
Reference in New Issue
Block a user