Add support for AdGuard's noop (_) network filter option · gorhill/uBlock@33b409d (original) (raw)

Original file line number Diff line number Diff line change
@@ -798,6 +798,7 @@ export class AstFilterParser {
798 798 this.reUnescapeCommas = /((?:^|[^\\])(?:\\\\)*)\\,/g;
799 799 this.reUnescapeSingleQuotes = /((?:^|[^\\])(?:\\\\)*)\\'/g;
800 800 this.reUnescapeDoubleQuotes = /((?:^|[^\\])(?:\\\\)*)\\"/g;
801 +this.reNoopOption = /^_+$/;
801 802 }
802 803
803 804 parse(raw) {
@@ -1854,13 +1855,21 @@ export class AstFilterParser {
1854 1855 const equalPos = s.indexOf('=');
1855 1856 const nameEnd = equalPos !== -1 ? equalPos : s.length;
1856 1857 const name = s.slice(nameBeg, nameEnd);
1857 -const nodeOptionType = nodeTypeFromOptionName.get(name) |
1858 +let nodeOptionType = nodeTypeFromOptionName.get(name);
1859 +if ( nodeOptionType === undefined ) {
1860 +nodeOptionType = this.reNoopOption.test(name)
1861 + ? NODE_TYPE_NET_OPTION_NAME_NOOP
1862 + : NODE_TYPE_NET_OPTION_NAME_UNKNOWN;
1863 +}
1858 1864 next = this.allocTypedNode(
1859 1865 nodeOptionType,
1860 1866 parentBeg + nameBeg,
1861 1867 parentBeg + nameEnd
1862 1868 );
1863 -if ( this.getBranchFromType(nodeOptionType) !== 0 ) {
1869 +if (
1870 +nodeOptionType !== NODE_TYPE_NET_OPTION_NAME_NOOP &&
1871 +this.getBranchFromType(nodeOptionType) !== 0
1872 +) {
1864 1873 this.addNodeFlags(parent, NODE_FLAG_ERROR);
1865 1874 this.addFlags(AST_FLAG_HAS_ERROR);
1866 1875 this.astError = AST_ERROR_OPTION_DUPLICATE;