From 33b409dd5baee1fd48a02bac757dc599373f1aa5 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 30 Jun 2023 16:09:21 -0400 Subject: [PATCH] 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. --- src/js/static-filtering-parser.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index fb0fcc641..598dd7880 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -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;