Skip to content

Commit

Permalink
Add support for AdGuard's noop (_) network filter option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Jun 30, 2023
1 parent b44815f commit 33b409d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ export class AstFilterParser {
this.reUnescapeCommas = /((?:^|[^\\])(?:\\\\)*)\\,/g;
this.reUnescapeSingleQuotes = /((?:^|[^\\])(?:\\\\)*)\\'/g;
this.reUnescapeDoubleQuotes = /((?:^|[^\\])(?:\\\\)*)\\"/g;
this.reNoopOption = /^_+$/;
}

parse(raw) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 33b409d

Please sign in to comment.