From 3789259fc922568283d041306bbacd0618945b25 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 17 Jul 2020 10:08:08 -0400 Subject: [PATCH] Consider an empty pattern with anchors to be dubious Related issue: - https://github.com/ryanbr/fanboy-adblock/issues/1384 --- src/js/codemirror/ubo-static-filtering.js | 10 +++++----- src/js/static-filtering-parser.js | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index de9af1feb..4a7e9d026 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -252,16 +252,16 @@ CodeMirror.defineMode('ubo-static-filtering', function() { if ( parser.category === parser.CATComment ) { return colorCommentSpan(stream); } - if ( (parser.slices[parserSlot] & parser.BITIgnore) !== 0 ) { - stream.pos += parser.slices[parserSlot+2]; - parserSlot += 3; - return 'comment'; - } if ( (parser.slices[parserSlot] & parser.BITError) !== 0 ) { stream.pos += parser.slices[parserSlot+2]; parserSlot += 3; return 'error'; } + if ( (parser.slices[parserSlot] & parser.BITIgnore) !== 0 ) { + stream.pos += parser.slices[parserSlot+2]; + parserSlot += 3; + return 'comment'; + } if ( parser.category === parser.CATStaticExtFilter ) { return colorExtSpan(stream); } diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 2e48d6d47..7610ea580 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -636,7 +636,11 @@ const Parser = class { this.toASCII(true) === false ) ) { - this.markSpan(this.patternSpan, BITError); + this.markSlices( + this.patternLeftAnchorSpan.i, + this.optionsAnchorSpan.i, + BITError + ); } this.netOptionsIterator.init(); } @@ -908,12 +912,17 @@ const Parser = class { // Examples of dubious filter content: // - Spaces characters // - Single character other than `*` wildcard + // - Zero-length pattern with anchors + // https://github.com/ryanbr/fanboy-adblock/issues/1384 patternIsDubious() { return hasBits(this.patternBits, BITSpace) || ( this.patternBits !== BITAsterisk && - this.optionsSpan.len === 0 && - this.patternSpan.len === 3 && - this.slices[this.patternSpan.i+2] === 1 + this.optionsSpan.len === 0 && ( + this.patternSpan.len === 0 && + this.patternLeftAnchorSpan.len !== 0 || + this.patternSpan.len === 3 && + this.slices[this.patternSpan.i+2] === 1 + ) ); }