1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-18 17:02:27 +02:00

Fix regression of reverse-lookup of scriptlet filters in logger

Related commit:
- 5552d6717d
This commit is contained in:
Raymond Hill 2019-07-05 11:44:40 -04:00
parent e107b6bcf1
commit f930da7ad6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 17 additions and 24 deletions

View File

@ -139,8 +139,8 @@ const µBlock = (function() { // jshint ignore:line
// Read-only // Read-only
systemSettings: { systemSettings: {
compiledMagic: 17, // Increase when compiled format changes compiledMagic: 18, // Increase when compiled format changes
selfieMagic: 17 // Increase when selfie format changes selfieMagic: 18 // Increase when selfie format changes
}, },
restoreBackupSettings: { restoreBackupSettings: {

View File

@ -189,21 +189,20 @@
return normalized; return normalized;
}; };
const lookupScriptlet = function(raw, reng, toInject) { const lookupScriptlet = function(rawToken, reng, toInject) {
const normalized = normalizeRawToken(raw); if ( toInject.has(rawToken) ) { return; }
if ( toInject.has(normalized) ) { return; }
if ( scriptletCache.resetTime < reng.modifyTime ) { if ( scriptletCache.resetTime < reng.modifyTime ) {
scriptletCache.reset(); scriptletCache.reset();
} }
let content = scriptletCache.lookup(normalized); let content = scriptletCache.lookup(rawToken);
if ( content === undefined ) { if ( content === undefined ) {
const pos = normalized.indexOf(','); const pos = rawToken.indexOf(',');
let token, args; let token, args;
if ( pos === -1 ) { if ( pos === -1 ) {
token = normalized; token = rawToken;
} else { } else {
token = normalized.slice(0, pos).trim(); token = rawToken.slice(0, pos).trim();
args = normalized.slice(pos + 1).trim(); args = rawToken.slice(pos + 1).trim();
} }
content = reng.resourceContentFromName( content = reng.resourceContentFromName(
`${token}.js`, `${token}.js`,
@ -218,9 +217,9 @@
'try {\n' + 'try {\n' +
content + '\n' + content + '\n' +
'} catch ( e ) { }'; '} catch ( e ) { }';
scriptletCache.add(normalized, content); scriptletCache.add(rawToken, content);
} }
toInject.set(normalized, content); toInject.set(rawToken, content);
}; };
// Fill template placeholders. Return falsy if: // Fill template placeholders. Return falsy if:
@ -271,10 +270,11 @@
writer.select(1001); writer.select(1001);
// Only exception filters are allowed to be global. // Only exception filters are allowed to be global.
const normalized = normalizeRawToken(parsed.suffix);
if ( parsed.hostnames.length === 0 ) { if ( parsed.hostnames.length === 0 ) {
if ( parsed.exception ) { if ( parsed.exception ) {
writer.push([ 32, '', 1, parsed.suffix ]); writer.push([ 32, '', 1, normalized ]);
} }
return; return;
} }
@ -295,7 +295,7 @@
} else if ( negated ) { } else if ( negated ) {
kind |= 1; kind |= 1;
} }
writer.push([ 32, hn, kind, parsed.suffix ]); writer.push([ 32, hn, kind, normalized ]);
} }
}; };
@ -360,23 +360,16 @@
if ( scriptletsRegister.size === 0 ) { return; } if ( scriptletsRegister.size === 0 ) { return; }
// Normalize dictionary of exceptions
// TODO: Eventually remove this code when normalized token usage is
// widespread and it can safely becomes the only valid syntax.
for ( const rawToken of exceptions ) {
exceptions.add(normalizeRawToken(rawToken));
}
// Return an array of scriptlets, and log results if needed. // Return an array of scriptlets, and log results if needed.
const out = []; const out = [];
const loggerEnabled = µb.logger.enabled; const loggerEnabled = µb.logger.enabled;
for ( const [ normalized, code ] of scriptletsRegister ) { for ( const [ rawToken, code ] of scriptletsRegister ) {
const isException = exceptions.has(normalized); const isException = exceptions.has(rawToken);
if ( isException === false ) { if ( isException === false ) {
out.push(code); out.push(code);
} }
if ( loggerEnabled ) { if ( loggerEnabled ) {
logOne(isException, normalized, request); logOne(isException, rawToken, request);
} }
} }