1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00

code review re. 60f60c2c97

This commit is contained in:
gorhill 2016-08-31 05:19:16 -04:00
parent 35b46cab4c
commit d4ce29397a
2 changed files with 13 additions and 7 deletions

View File

@ -55,7 +55,7 @@ var ThirdParty = 2 << 2;
var AnyType = 0 << 4; var AnyType = 0 << 4;
var typeNameToTypeValue = { var typeNameToTypeValue = {
'notype': 0 << 4, 'no_type': 0 << 4,
'stylesheet': 1 << 4, 'stylesheet': 1 << 4,
'image': 2 << 4, 'image': 2 << 4,
'object': 3 << 4, 'object': 3 << 4,
@ -2336,8 +2336,8 @@ FilterContainer.prototype.matchTokens = function(bucket, url) {
FilterContainer.prototype.matchStringExactType = function(context, requestURL, requestType) { FilterContainer.prototype.matchStringExactType = function(context, requestURL, requestType) {
// Be prepared to support unknown types // Be prepared to support unknown types
var type = typeNameToTypeValue[requestType] || 0; var type = typeNameToTypeValue[requestType];
if ( type === 0 ) { if ( type === undefined ) {
return undefined; return undefined;
} }
@ -2436,7 +2436,7 @@ FilterContainer.prototype.matchString = function(context) {
var type = typeNameToTypeValue[context.requestType]; var type = typeNameToTypeValue[context.requestType];
if ( type === undefined ) { if ( type === undefined ) {
type = typeOtherValue; type = typeOtherValue;
} else if ( type > typeOtherValue ) { } else if ( type === 0 || type > typeOtherValue ) {
return this.matchStringExactType(context, context.requestURL, context.requestType); return this.matchStringExactType(context, context.requestURL, context.requestType);
} }

View File

@ -169,7 +169,7 @@ var onBeforeRootFrameRequest = function(details) {
pageDomain: requestDomain, pageDomain: requestDomain,
requestURL: requestURL, requestURL: requestURL,
requestHostname: requestHostname, requestHostname: requestHostname,
requestType: 'notype' requestType: 'main_frame'
}; };
var result = ''; var result = '';
@ -196,12 +196,18 @@ var onBeforeRootFrameRequest = function(details) {
var snfe = µb.staticNetFilteringEngine; var snfe = µb.staticNetFilteringEngine;
// Check for specific block // Check for specific block
if ( result === '' && snfe.matchStringExactType(context, requestURL, 'main_frame') !== undefined ) { if (
result === '' &&
snfe.matchStringExactType(context, requestURL, 'main_frame') !== undefined
) {
result = snfe.toResultString(true); result = snfe.toResultString(true);
} }
// Check for generic block // Check for generic block
if ( result === '' && snfe.matchString(context) !== undefined ) { if (
result === '' &&
snfe.matchStringExactType(context, requestURL, 'no_type') !== undefined
) {
result = snfe.toResultString(true); result = snfe.toResultString(true);
// https://github.com/chrisaljoudi/uBlock/issues/1128 // https://github.com/chrisaljoudi/uBlock/issues/1128
// Do not block if the match begins after the hostname, except when // Do not block if the match begins after the hostname, except when