diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index f49ff3f06..b2177ec90 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -1,7 +1,7 @@ /******************************************************************************* uBlock Origin - a browser extension to block requests. - Copyright (C) 2018 Raymond Hill + Copyright (C) 2018-present Raymond Hill This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ CodeMirror.defineMode("ubo-static-filtering", function() { var reComment1 = /^\s*!/; var reComment2 = /^\s*#/; - var reExt = /^(\s*[^#]*)(#(?:#|@#|\$#|@\$#|\?#|@\?#))(.+)$/; + var reExt = /^(\s*[^#]*)(#@?(?:\$\??|\?)?#)(.+)$/; var reNet = /^(.*?)(?:(\$)([^$]+)?)?$/; var reNetAllow = /^\s*@@/; var lineStyle = null; diff --git a/src/js/static-ext-filtering.js b/src/js/static-ext-filtering.js index 598d6bb01..724a69e0f 100644 --- a/src/js/static-ext-filtering.js +++ b/src/js/static-ext-filtering.js @@ -741,11 +741,22 @@ if ( rpos === -1 ) { return false; } } + // https://github.com/AdguardTeam/AdguardFilters/commit/4fe02d73cee6 + // AdGuard also uses `$?` to force inline-based style rather than + // stylesheet-based style. // Coarse-check that the anchor is valid. - // `##`: l = 1 - // `#@#`, `#$#`, `#%#`, `#?#`: l = 2 - // `#@$#`, `#@%#`, `#@?#`: l = 3 - if ( (rpos - lpos) > 3 ) { return false; } + // `##`: l === 1 + // `#@#`, `#$#`, `#%#`, `#?#`: l === 2 + // `#@$#`, `#@%#`, `#@?#`, `#$?#`: l === 3 + // `#@$?#`: l === 4 + const anchorLen = rpos - lpos; + if ( anchorLen > 4 ) { return false; } + if ( + anchorLen > 1 && + /^@?(?:\$\??|%|\?)$/.test(raw.slice(lpos + 1, rpos)) === false + ) { + return false; + } // Extract the selector. let suffix = raw.slice(rpos + 1).trim(); @@ -763,9 +774,8 @@ if ( cCode !== 0x23 /* '#' */ && cCode !== 0x40 /* '@' */ ) { // Adguard's scriptlet injection: not supported. if ( cCode === 0x25 /* '%' */ ) { return true; } - // Not a known extended filter. - if ( cCode !== 0x24 /* '$' */ && cCode !== 0x3F /* '?' */ ) { - return false; + if ( cCode === 0x3F /* '?' */ && anchorLen > 2 ) { + cCode = raw.charCodeAt(rpos - 2); } // Adguard's style injection: translate to uBO's format. if ( cCode === 0x24 /* '$' */ ) {