From 05476e9fd3369cba258384ad2bfa50e8acd5f590 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 25 Nov 2015 10:05:23 -0500 Subject: [PATCH] code review --- assets/checksums.txt | 2 +- assets/ublock/redirect.txt | 5 ++++- src/js/redirect-engine.js | 27 +++++++++++++++++++-------- src/js/static-net-filtering.js | 3 +++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/assets/checksums.txt b/assets/checksums.txt index 5120de24f..fc6a03253 100644 --- a/assets/checksums.txt +++ b/assets/checksums.txt @@ -3,7 +3,7 @@ e65fbcaa573c028770f1d0afada55672 assets/ublock/redirect-resources.txt 7a04294b44b88baa34cf3e4bfe0e59db assets/ublock/privacy.txt b2dbf435507aa0262b289c67cbef2142 assets/ublock/filters.txt 146704ad1c0393e342afdb416762c183 assets/ublock/badware.txt -4b3df06f0b27c57cea0006ae559e078b assets/ublock/redirect.txt +d3e766dbd8624423a7e5fea878580ee9 assets/ublock/redirect.txt e1a6bb625a9ee59cc57f6b77c76108ff assets/ublock/filter-lists.json f549ce62117ff04b63c177227b5cb288 assets/thirdparties/easylist-downloads.adblockplus.org/easyprivacy.txt da709032e6b674de08b7561e3f4e552d assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt diff --git a/assets/ublock/redirect.txt b/assets/ublock/redirect.txt index 8a6712919..832f80073 100644 --- a/assets/ublock/redirect.txt +++ b/assets/ublock/redirect.txt @@ -1,4 +1,7 @@ -# uBlock Origin -- To redirect blocked resources to friendlier contents. +# uBlock Origin -- To redirect blocked resources to neutered contents. +# +# The redirect tokens reference an entry in the resource library: +# https://github.com/gorhill/uBlock/blob/master/assets/ublock/redirect-resources.txt ||s3.amazonaws.com/homad-global-configs.schneevonmorgen.com/hd-main.js$script,domain=cdnapi.kaltura.com,redirect=hd-main.js ||hgc.svonm.com/hd-main.js$script,domain=cdnapi.kaltura.com,redirect=hd-main.js diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index 70fce7426..670093b5e 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -130,7 +130,7 @@ RedirectEngine.prototype.fromCompiledRule = function(line) { RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) { var matches = this.reFilterParser.exec(line); if ( matches === null || matches.length !== 4 ) { - return ''; + return; } var pattern = (matches[1] + matches[2]).replace(/[.+?{}()|[\]\\]/g, '\\$&') @@ -138,7 +138,7 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) { .replace(/\*/g, '.*?'); var des = matches[1]; - var types = []; + var type; var redirect = ''; var srcs = []; var options = matches[3].split(','), option; @@ -151,20 +151,24 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) { srcs = option.slice(7).split('|'); continue; } + // One and only one type must be specified. if ( option in this.supportedTypes ) { - types.push(option); + if ( type !== undefined ) { + return; + } + type = option; continue; } } // Need a resource token. if ( redirect === '' ) { - return ''; + return; } - // Need one single type (not negated). - if ( types.length !== 1 || types[0].charAt(0) === '~' ) { - return ''; + // Need one single type -- not negated. + if ( type === undefined || type.charAt(0) === '~' ) { + return; } if ( des === '' ) { @@ -179,10 +183,17 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) { var i = srcs.length, src; while ( i-- ) { src = srcs[i]; + if ( src === '' ) { + continue; + } if ( src.charAt(0) === '~' ) { continue; } - out.push(srcs[i] + '\t' + des + '\t' + types[0] + '\t' + pattern + '\t' + redirect); + // Need at least one specific src or des. + if ( src === '*' && des === '*' ) { + continue; + } + out.push(src + '\t' + des + '\t' + type + '\t' + pattern + '\t' + redirect); } return out; diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 01640fd23..5764adfa7 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -2053,6 +2053,9 @@ FilterContainer.prototype.compileToAtomicFilter = function(filterClass, parsed, } var redirects = µb.redirectEngine.compileRuleFromStaticFilter(parsed.raw); + if ( Array.isArray(redirects) === false ) { + return; + } var i = redirects.length; while ( i-- ) { out.push('n\v\v\v=>\v' + redirects[i]);