mirror of https://github.com/gorhill/uBlock.git
This commit is contained in:
parent
ab90baab81
commit
e21705dea6
|
@ -307,7 +307,7 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) {
|
||||||
var µburi = µBlock.URI,
|
var µburi = µBlock.URI,
|
||||||
des = matches[1] || '',
|
des = matches[1] || '',
|
||||||
pattern = (des + matches[2]).replace(/[.+?{}()|[\]\/\\]/g, '\\$&')
|
pattern = (des + matches[2]).replace(/[.+?{}()|[\]\/\\]/g, '\\$&')
|
||||||
.replace(/\^/g, '[^\\w\\d%-]')
|
.replace(/\^/g, '[^\\w.%-]')
|
||||||
.replace(/\*/g, '.*?'),
|
.replace(/\*/g, '.*?'),
|
||||||
type,
|
type,
|
||||||
redirect = '',
|
redirect = '',
|
||||||
|
|
|
@ -2134,9 +2134,10 @@ FilterContainer.prototype.compile = function(raw, writer) {
|
||||||
if (
|
if (
|
||||||
parsed.hostnamePure &&
|
parsed.hostnamePure &&
|
||||||
parsed.domainOpt === '' &&
|
parsed.domainOpt === '' &&
|
||||||
parsed.dataType === undefined &&
|
parsed.dataType === undefined
|
||||||
this.compileHostnameOnlyFilter(parsed, writer)
|
|
||||||
) {
|
) {
|
||||||
|
parsed.tokenHash = this.dotTokenHash;
|
||||||
|
this.compileToAtomicFilter(parsed, parsed.f, writer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2194,52 +2195,32 @@ FilterContainer.prototype.compile = function(raw, writer) {
|
||||||
fdata.push(fwrapped);
|
fdata.push(fwrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.compileToAtomicFilter(fdata, parsed, writer);
|
this.compileToAtomicFilter(parsed, fdata, writer);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Using fast/compact dictionary when filter is a pure hostname.
|
FilterContainer.prototype.compileToAtomicFilter = function(
|
||||||
|
parsed,
|
||||||
|
fdata,
|
||||||
|
writer
|
||||||
|
) {
|
||||||
|
let descBits = parsed.action |
|
||||||
|
parsed.important |
|
||||||
|
parsed.party |
|
||||||
|
parsed.badFilter;
|
||||||
|
let type = parsed.types;
|
||||||
|
|
||||||
FilterContainer.prototype.compileHostnameOnlyFilter = function(parsed, writer) {
|
// Typeless
|
||||||
// Can't fit the filter in a pure hostname dictionary.
|
|
||||||
// https://github.com/gorhill/uBlock/issues/1757
|
|
||||||
// This should no longer happen with fix to above issue.
|
|
||||||
//if ( parsed.domainOpt.length !== 0 ) {
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
|
|
||||||
var descBits = parsed.action | parsed.important | parsed.party | parsed.badFilter;
|
|
||||||
|
|
||||||
var type = parsed.types;
|
|
||||||
if ( type === 0 ) {
|
|
||||||
writer.push([ descBits, this.dotTokenHash, parsed.f ]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bitOffset = 1;
|
|
||||||
do {
|
|
||||||
if ( type & 1 ) {
|
|
||||||
writer.push([ descBits | (bitOffset << 4), this.dotTokenHash, parsed.f ]);
|
|
||||||
}
|
|
||||||
bitOffset += 1;
|
|
||||||
type >>>= 1;
|
|
||||||
} while ( type !== 0 );
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
FilterContainer.prototype.compileToAtomicFilter = function(fdata, parsed, writer) {
|
|
||||||
var descBits = parsed.action | parsed.important | parsed.party | parsed.badFilter,
|
|
||||||
type = parsed.types;
|
|
||||||
if ( type === 0 ) {
|
if ( type === 0 ) {
|
||||||
writer.push([ descBits, parsed.tokenHash, fdata ]);
|
writer.push([ descBits, parsed.tokenHash, fdata ]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var bitOffset = 1;
|
|
||||||
|
// Specific type(s)
|
||||||
|
let bitOffset = 1;
|
||||||
do {
|
do {
|
||||||
if ( type & 1 ) {
|
if ( type & 1 ) {
|
||||||
writer.push([ descBits | (bitOffset << 4), parsed.tokenHash, fdata ]);
|
writer.push([ descBits | (bitOffset << 4), parsed.tokenHash, fdata ]);
|
||||||
|
@ -2250,22 +2231,13 @@ FilterContainer.prototype.compileToAtomicFilter = function(fdata, parsed, writer
|
||||||
|
|
||||||
// Only static filter with an explicit type can be redirected. If we reach
|
// Only static filter with an explicit type can be redirected. If we reach
|
||||||
// this point, it's because there is one or more explicit type.
|
// this point, it's because there is one or more explicit type.
|
||||||
if ( !parsed.redirect ) {
|
if ( parsed.badFilter === 0 && parsed.redirect ) {
|
||||||
return;
|
let redirects = µb.redirectEngine.compileRuleFromStaticFilter(parsed.raw);
|
||||||
}
|
if ( Array.isArray(redirects) ) {
|
||||||
|
for ( let redirect of redirects ) {
|
||||||
if ( parsed.badFilter ) {
|
writer.push([ typeNameToTypeValue.redirect, redirect ]);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var redirects = µb.redirectEngine.compileRuleFromStaticFilter(parsed.raw);
|
|
||||||
if ( Array.isArray(redirects) === false ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
descBits = typeNameToTypeValue.redirect;
|
|
||||||
var i = redirects.length;
|
|
||||||
while ( i-- ) {
|
|
||||||
writer.push([ descBits, redirects[i] ]);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue