From e52da39839c9cd7e70da9cc74b1514a99e0122ba Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 3 Jul 2023 06:54:46 -0400 Subject: [PATCH] Fine tune network filter option anchor detection The change allows to better parse AdGuard filters with `replace=` option when the value to the `replace=` option contains dollar sign character `$`. uBO will still reject these filters but will better identify which dollar sign `$` is the real filter option anchor. --- src/js/static-filtering-parser.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 598dd7880dc39..c7035767ece6c 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1387,9 +1387,17 @@ export class AstFilterParser { if ( j === -1 ) { return end; } if ( (j+1) === end ) { return end; } for (;;) { - if ( j !== start && s.charCodeAt(j-1) === 0x24 /* $ */ ) { return -1; } - const c = s.charCodeAt(j+1); - if ( c !== 0x29 /* ) */ && c !== 0x2F /* / */ && c !== 0x7C /* | */ ) { return j; } + const before = s.charCodeAt(j-1); + if ( j !== start && before === 0x24 /* $ */ ) { return -1; } + const after = s.charCodeAt(j+1); + if ( + after !== 0x29 /* ) */ && + after !== 0x2F /* / */ && + after !== 0x7C /* | */ && + before !== 0x5C /* \ */ + ) { + return j; + } if ( j <= start ) { break; } j = s.lastIndexOf('$', j-1); if ( j === -1 ) { break; }