From 874e92af2de67d852f37e4be5f89548659c1be25 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 10 Jul 2019 17:24:01 -0400 Subject: [PATCH] Fix regression in URL rules validation Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/665 Regression: - https://github.com/gorhill/uBlock/commit/2f63fb3fd451bd3ca5795cfd1be46335ce6d3da7 --- src/js/codemirror/ubo-dynamic-filtering.js | 7 +++++-- src/js/url-net-filtering.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/js/codemirror/ubo-dynamic-filtering.js b/src/js/codemirror/ubo-dynamic-filtering.js index a3c408f23..4d1d252cc 100644 --- a/src/js/codemirror/ubo-dynamic-filtering.js +++ b/src/js/codemirror/ubo-dynamic-filtering.js @@ -65,7 +65,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => { }; const isURLRule = ( ) => { - return /^[\w-_]+:\/\/[^/]+\//.test(tokens[1]); + return tokens[1].indexOf('://') > 0; }; const skipToEnd = (stream, style = null) => { @@ -132,7 +132,10 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => { return null; } // URL rule - if ( /[^a-z_-]+/.test(token) || invalidURLRuleTypes.has(token) ) { + if ( + /[^a-z_-]/.test(token) && token !== '*' || + invalidURLRuleTypes.has(token) + ) { return skipToEnd(stream, 'error'); } return null; diff --git a/src/js/url-net-filtering.js b/src/js/url-net-filtering.js index d6d44111b..aa6a9e232 100644 --- a/src/js/url-net-filtering.js +++ b/src/js/url-net-filtering.js @@ -340,8 +340,11 @@ URLNetFiltering.prototype.fromString = function(text) { URLNetFiltering.prototype.validateRuleParts = function(parts) { if ( parts.length !== 4 ) { return; } - if ( parts[1].indexOf('://') === -1 ) { return; } - if ( /[^a-z_-]+/.test(parts[2]) || knownInvalidTypes.has(parts[2]) ) { + if ( parts[1].indexOf('://') <= 0 ) { return; } + if ( + /[^a-z_-]/.test(parts[2]) && parts[2] !== '*' || + knownInvalidTypes.has(parts[2]) + ) { return; } if ( nameToActionMap.hasOwnProperty(parts[3]) === false ) { return; }