1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

Add support for AdGuard's noop (_) network filter option

Reference:
- https://adguard.com/kb/general/ad-filtering/create-own-filters/#noop-modifier

uBO already supported the noop filter option `_` to allow filter
authors to resolve possible ambiguities arising when crafting network
filters with many options.

AdGuard extended the semantic of the `_` option to also resolve
readability issues by supporting multiple instances of the `_` option
in a single filter, and also by supporting any number of consecutive
`_` in a single noop filter option.
This commit is contained in:
Raymond Hill 2023-06-30 16:09:21 -04:00
parent b44815f0c8
commit 33b409dd5b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -798,6 +798,7 @@ export class AstFilterParser {
this.reUnescapeCommas = /((?:^|[^\\])(?:\\\\)*)\\,/g;
this.reUnescapeSingleQuotes = /((?:^|[^\\])(?:\\\\)*)\\'/g;
this.reUnescapeDoubleQuotes = /((?:^|[^\\])(?:\\\\)*)\\"/g;
this.reNoopOption = /^_+$/;
}
parse(raw) {
@ -1854,13 +1855,21 @@ export class AstFilterParser {
const equalPos = s.indexOf('=');
const nameEnd = equalPos !== -1 ? equalPos : s.length;
const name = s.slice(nameBeg, nameEnd);
const nodeOptionType = nodeTypeFromOptionName.get(name) || NODE_TYPE_NET_OPTION_NAME_UNKNOWN;
let nodeOptionType = nodeTypeFromOptionName.get(name);
if ( nodeOptionType === undefined ) {
nodeOptionType = this.reNoopOption.test(name)
? NODE_TYPE_NET_OPTION_NAME_NOOP
: NODE_TYPE_NET_OPTION_NAME_UNKNOWN;
}
next = this.allocTypedNode(
nodeOptionType,
parentBeg + nameBeg,
parentBeg + nameEnd
);
if ( this.getBranchFromType(nodeOptionType) !== 0 ) {
if (
nodeOptionType !== NODE_TYPE_NET_OPTION_NAME_NOOP &&
this.getBranchFromType(nodeOptionType) !== 0
) {
this.addNodeFlags(parent, NODE_FLAG_ERROR);
this.addFlags(AST_FLAG_HAS_ERROR);
this.astError = AST_ERROR_OPTION_DUPLICATE;