diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 5b9f09dea..d0059477a 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -319,9 +319,6 @@ vAPI.tabs.open = function(details) { vAPI.tabs.replace = function(tabId, url) { var targetURL = url; - if ( typeof targetURL !== 'string' || targetURL === '' ) { - return; - } // extension pages if ( /^[\w-]{2,}:/.test(targetURL) !== true ) { @@ -340,7 +337,6 @@ vAPI.tabs.replace = function(tabId, url) { if ( chrome.runtime.lastError ) { return; } - }); }; diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index 645221a9d..953535882 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -377,6 +377,24 @@ /******************************************************************************/ + // Replace the URL of a tab. Noop if the tab does not exist. + + vAPI.tabs.replace = function(tabId, url) { + var targetURL = url; + + // extension pages + if ( /^[\w-]{2,}:/.test(targetURL) !== true ) { + targetURL = vAPI.getURL(targetURL); + } + + var tab = this.stack[tabId]; + if ( tab ) { + tab.url = targetURL; + } + }; + + /******************************************************************************/ + vAPI.tabs.remove = function(tabIds) { if(tabIds instanceof SafariBrowserTab) { tabIds = this.getTabId(tabIds); diff --git a/src/js/document-blocked.js b/src/js/document-blocked.js index f830966b1..f1b6afd7d 100644 --- a/src/js/document-blocked.js +++ b/src/js/document-blocked.js @@ -96,6 +96,8 @@ if ( window.history.length > 1 ) { uDom('#proceedTemporary').attr('href', details.url).on('click', proceedTemporary); uDom('#proceedPermanent').attr('href', details.url).on('click', proceedPermanent); +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index de6f04a68..324fb778d 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -96,8 +96,8 @@ var reURLPostHostnameAnchors = /[\/?#]/; var pageHostnameRegister = ''; var requestHostnameRegister = ''; -var filterRegister = null; -var categoryRegister = ''; +//var filterRegister = null; +//var categoryRegister = ''; /******************************************************************************/ diff --git a/src/js/traffic.js b/src/js/traffic.js index 10c1af180..75cf94219 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -219,6 +219,11 @@ var onBeforeRootFrameRequest = function(details) { // Filtering if ( result === '' && µb.getNetFilteringSwitch(requestURL) ) { result = µb.staticNetFilteringEngine.matchString(context); + // https://github.com/gorhill/uBlock/issues/1128 + // Do not block if the match begins after the hostname. + if ( result !== '' ) { + result = toBlockDocResult(requestURL, requestHostname, result); + } } // Log @@ -246,6 +251,60 @@ var onBeforeRootFrameRequest = function(details) { /******************************************************************************/ +var toBlockDocResult = function(url, hostname, result) { + if ( result.charAt(1) !== 'b' ) { + return ''; + } + + // Quick test: if the result starts with `|` or `||`, then this means the + // match is before the path part of the URL for sure. + // Examples: sb:|http:// sb:||example.com^ + if ( result.charAt(3) === '|' ) { + return result; + } + + // Make a regex out of the result + var reText = result.slice(3); + var pos = reText.indexOf('$'); + if ( pos > 0 ) { + reText = reText.slice(0, pos); + } + + // Matches whole URL + if ( reText === '*' ) { + return result; + } + + // We are going to have to take the long way to find out + if ( reText.charAt(0) === '/' && reText.slice(-1) === '/' ) { + reText = reText.slice(1, -1); + } else { + reText = reText + .replace(/\./g, '\\.') + .replace(/\?/g, '\\?') + .replace(/^\|\|/, '') + .replace(/\^/g, '.') + .replace(/^\|/g, '^') + .replace(/\|$/g, '$') + .replace(/\*/g, '.*'); + } + + var re = new RegExp(reText, 'gi'); + var matches = re.exec(url); + if ( matches === null ) { + return ''; + } + + // verify that the match starts before the path + if ( matches.index < url.indexOf(hostname) + hostname.length ) { + return result; + } + + return ''; +}; + +/******************************************************************************/ + // Intercept and filter behind-the-scene requests. var onBeforeBehindTheSceneRequest = function(details) {