Skip to content

Commit

Permalink
Use +js name for logging.
Browse files Browse the repository at this point in the history
fix uBlockOrigin/uBlock-issues#209 

Co-authored-by:  gorhill <585534+gorhill@users.noreply.github.com>
  • Loading branch information
hawkeye116477 and gorhill committed Jun 28, 2020
1 parent ebf1b04 commit 3561050
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ var µBlock = (function() { // jshint ignore:line

// read-only
systemSettings: {
compiledMagic: 1,
compiledMagic: 2,
selfieMagic: 1
},

Expand Down
26 changes: 13 additions & 13 deletions src/js/scriptlet-filtering.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2017 Raymond Hill
Copyright (C) 2017-present Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -97,7 +97,7 @@
'cosmetic',
{
source: 'cosmetic',
raw: (isException ? '#@#' : '##') + 'script:inject(' + token + ')'
raw: (isException ? '#@#' : '##') + '+js(' + token + ')'
},
'dom',
details.url,
Expand Down Expand Up @@ -134,14 +134,14 @@
// Ignore instances of exception filter with negated hostnames,
// because there is no way to create an exception to an exception.

var µburi = µb.URI;
let µburi = µb.URI;

for ( var hostname of parsed.hostnames ) {
var negated = hostname.charCodeAt(0) === 0x7E /* '~' */;
for ( let hostname of parsed.hostnames ) {
let negated = hostname.charCodeAt(0) === 0x7E /* '~' */;
if ( negated ) {
hostname = hostname.slice(1);
}
var hash = µburi.domainFromHostname(hostname);
let hash = µburi.domainFromHostname(hostname);
if ( parsed.exception ) {
if ( negated ) { continue; }
hash = '!' + hash;
Expand All @@ -153,27 +153,27 @@
};

// 01234567890123456789
// script:inject(token[, arg[, ...]])
// ^ ^
// 14 -1
// +js(token[, arg[, ...]])
// ^ ^
// 4 -1

api.fromCompiledContent = function(reader) {
// 1001 = scriptlet injection
reader.select(1001);

while ( reader.next() ) {
acceptedCount += 1;
var fingerprint = reader.fingerprint();
let fingerprint = reader.fingerprint();
if ( duplicates.has(fingerprint) ) {
discardedCount += 1;
continue;
}
duplicates.add(fingerprint);
var args = reader.args();
let args = reader.args();
if ( args.length < 4 ) { continue; }
scriptletDB.add(
args[1],
{ hostname: args[2], token: args[3].slice(14, -1) }
{ hostname: args[2], token: args[3].slice(4, -1) }
);
}
};
Expand Down Expand Up @@ -223,7 +223,7 @@
exceptionsRegister.add(entry.token);
}

// Return an array of scriptlets, and log results if needed.
// Return an array of scriptlets, and log results if needed.
var out = [],
logger = µb.logger.isEnabled() ? µb.logger : null,
isException;
Expand Down
31 changes: 10 additions & 21 deletions src/js/static-ext-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@
})();

api.compile = function(raw, writer) {
var lpos = raw.indexOf('#');
let lpos = raw.indexOf('#');
if ( lpos === -1 ) { return false; }
var rpos = lpos + 1;
let rpos = lpos + 1;
if ( raw.charCodeAt(rpos) !== 0x23 /* '#' */ ) {
rpos = raw.indexOf('#', rpos + 1);
if ( rpos === -1 ) { return false; }
Expand All @@ -615,7 +615,7 @@
if ( (rpos - lpos) > 3 ) { return false; }

// Extract the selector.
var suffix = raw.slice(rpos + 1).trim();
let suffix = raw.slice(rpos + 1).trim();
if ( suffix.length === 0 ) { return false; }
parsed.suffix = suffix;

Expand All @@ -626,7 +626,7 @@
// We have an Adguard/ABP cosmetic filter if and only if the
// character is `$`, `%` or `?`, otherwise it's not a cosmetic
// filter.
var cCode = raw.charCodeAt(rpos - 1);
let cCode = raw.charCodeAt(rpos - 1);
if ( cCode !== 0x23 /* '#' */ && cCode !== 0x40 /* '@' */ ) {
// Adguard's scriptlet injection: not supported.
if ( cCode === 0x25 /* '%' */ ) { return true; }
Expand All @@ -649,37 +649,26 @@
if ( lpos === 0 ) {
parsed.hostnames = emptyArray;
} else {
var prefix = raw.slice(0, lpos);
let prefix = raw.slice(0, lpos);
parsed.hostnames = prefix.split(reHostnameSeparator);
if ( reHasUnicode.test(prefix) ) {
toASCIIHostnames(parsed.hostnames);
}
}

// Backward compatibility with deprecated syntax.
if ( suffix.startsWith('script:') ) {
// Scriptlet injection engine.
if ( suffix.startsWith('script:inject') ) {
µb.scriptletFilteringEngine.compile(parsed, writer);
return true;
}
// Script tag filtering: courtesy-conversion to HTML filtering.
if ( suffix.startsWith('script:contains') ) {
console.info(
'uBO: ##script:contains(...) is deprecated, ' +
'converting to ##^script:has-text(...)'
);
suffix = suffix.replace(/^script:contains/, '^script:has-text');
parsed.suffix = suffix;
suffix = parsed.suffix = '+js' + suffix.slice(13);
} else if ( suffix.startsWith('script:contains') ) {
suffix = parsed.suffix = '^script:has-text' + suffix.slice(15);
}
}

var c0 = suffix.charCodeAt(0);
let c0 = suffix.charCodeAt(0);

// New shorter syntax for scriptlet injection engine.
if ( c0 === 0x2B /* '+' */ && suffix.startsWith('+js') ) {
// Convert to deprecated syntax for now. Once 1.15.12 is
// widespread, `+js` form will be the official syntax.
parsed.suffix = 'script:inject' + parsed.suffix.slice(3);
µb.scriptletFilteringEngine.compile(parsed, writer);
return true;
}
Expand Down

0 comments on commit 3561050

Please sign in to comment.