This commit is contained in:
Raymond Hill 2018-07-19 09:40:39 -04:00
parent ab90baab81
commit e21705dea6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 26 additions and 54 deletions

View File

@ -307,7 +307,7 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) {
var µburi = µBlock.URI,
des = matches[1] || '',
pattern = (des + matches[2]).replace(/[.+?{}()|[\]\/\\]/g, '\\$&')
.replace(/\^/g, '[^\\w\\d%-]')
.replace(/\^/g, '[^\\w.%-]')
.replace(/\*/g, '.*?'),
type,
redirect = '',

View File

@ -2134,9 +2134,10 @@ FilterContainer.prototype.compile = function(raw, writer) {
if (
parsed.hostnamePure &&
parsed.domainOpt === '' &&
parsed.dataType === undefined &&
this.compileHostnameOnlyFilter(parsed, writer)
parsed.dataType === undefined
) {
parsed.tokenHash = this.dotTokenHash;
this.compileToAtomicFilter(parsed, parsed.f, writer);
return true;
}
@ -2194,52 +2195,32 @@ FilterContainer.prototype.compile = function(raw, writer) {
fdata.push(fwrapped);
}
this.compileToAtomicFilter(fdata, parsed, writer);
this.compileToAtomicFilter(parsed, fdata, writer);
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) {
// 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;
// Typeless
if ( type === 0 ) {
writer.push([ descBits, parsed.tokenHash, fdata ]);
return;
}
var bitOffset = 1;
// Specific type(s)
let bitOffset = 1;
do {
if ( type & 1 ) {
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
// this point, it's because there is one or more explicit type.
if ( !parsed.redirect ) {
return;
}
if ( parsed.badFilter ) {
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] ]);
if ( parsed.badFilter === 0 && parsed.redirect ) {
let redirects = µb.redirectEngine.compileRuleFromStaticFilter(parsed.raw);
if ( Array.isArray(redirects) ) {
for ( let redirect of redirects ) {
writer.push([ typeNameToTypeValue.redirect, redirect ]);
}
}
}
};