From a14dcecf8fdcc4f40407b33a6da7af9b3fb7803a Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 14 May 2019 09:29:45 -0400 Subject: [PATCH] Do not assume wildcards fall on label boundaries Related commit: - https://github.com/gorhill/uBlock/commit/fe0b7a0e0f77f0a34def117986dbb63530c2a9e3 Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/572#issuecomment-492223980 --- src/js/redirect-engine.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index 07753f88a..6a938b356 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -305,11 +305,14 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) { // https://github.com/uBlockOrigin/uBlock-issues/issues/572 // Extract best possible hostname. let deshn = des; - const pos = deshn.lastIndexOf('*'); + let pos = deshn.lastIndexOf('*'); if ( pos !== -1 ) { deshn = deshn.slice(pos + 1); - if ( deshn.charCodeAt(0) === 0x2E /* '.' */ ) { - deshn = deshn.replace(/\.+/, ''); + pos = deshn.indexOf('.'); + if ( pos !== -1 ) { + deshn = deshn.slice(pos + 1); + } else { + deshn = ''; } } @@ -334,7 +337,7 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) { srchns = option.slice(7).split('|'); continue; } - if ( option === 'first-party' || option === '1p' ) { + if ( (option === 'first-party' || option === '1p') && deshn !== '' ) { srchns.push(µBlock.URI.domainFromHostname(deshn) || deshn); continue; }