Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
this fixes #1128
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Mar 30, 2015
1 parent eb27478 commit 5b34efc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
4 changes: 0 additions & 4 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -340,7 +337,6 @@ vAPI.tabs.replace = function(tabId, url) {
if ( chrome.runtime.lastError ) {
return;
}

});
};

Expand Down
18 changes: 18 additions & 0 deletions platform/safari/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/js/document-blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/******************************************************************************/

})();

/******************************************************************************/
4 changes: 2 additions & 2 deletions src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ var reURLPostHostnameAnchors = /[\/?#]/;

var pageHostnameRegister = '';
var requestHostnameRegister = '';
var filterRegister = null;
var categoryRegister = '';
//var filterRegister = null;
//var categoryRegister = '';

/******************************************************************************/

Expand Down
59 changes: 59 additions & 0 deletions src/js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5b34efc

Please sign in to comment.