Fix regression when generating `data` URI in redirect engine

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/cpxm1v/

Put back erroneously removed code which enable to
generate a `data` URI from already encoded resources.
This commit is contained in:
Raymond Hill 2019-08-16 13:43:41 -04:00
parent 71dae6b30c
commit 6c73bd78f4
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 13 additions and 7 deletions

View File

@ -56,7 +56,7 @@
// Default to webext storage. Wrapped into promises if the API does not // Default to webext storage. Wrapped into promises if the API does not
// support returning promises. // support returning promises.
const promisified = (function() { const promisified = (( ) => {
try { try {
return browser.storage.local.get('_') instanceof Promise; return browser.storage.local.get('_') instanceof Promise;
} }
@ -394,19 +394,19 @@
if ( keys.length === 0 ) { return callback(); } if ( keys.length === 0 ) { return callback(); }
getDb().then(db => { getDb().then(db => {
if ( !db ) { return callback(); } if ( !db ) { return callback(); }
let finish = ( ) => { const finish = ( ) => {
if ( callback === undefined ) { return; } if ( callback === undefined ) { return; }
let cb = callback; let cb = callback;
callback = undefined; callback = undefined;
cb(); cb();
}; };
try { try {
let transaction = db.transaction(STORAGE_NAME, 'readwrite'); const transaction = db.transaction(STORAGE_NAME, 'readwrite');
transaction.oncomplete = transaction.oncomplete =
transaction.onerror = transaction.onerror =
transaction.onabort = finish; transaction.onabort = finish;
let table = transaction.objectStore(STORAGE_NAME); const table = transaction.objectStore(STORAGE_NAME);
for ( let key of keys ) { for ( const key of keys ) {
table.delete(key); table.delete(key);
} }
} catch (ex) { } catch (ex) {
@ -420,7 +420,7 @@
callback = noopfn; callback = noopfn;
} }
getDb().then(db => { getDb().then(db => {
let transaction = db.transaction(STORAGE_NAME, 'readwrite'); const transaction = db.transaction(STORAGE_NAME, 'readwrite');
transaction.oncomplete = transaction.oncomplete =
transaction.onerror = transaction.onerror =
transaction.onabort = ( ) => { transaction.onabort = ( ) => {

View File

@ -201,6 +201,8 @@ const RedirectEntry = class {
// cause leakage of extension id. See: // cause leakage of extension id. See:
// - https://stackoverflow.com/a/8056313 // - https://stackoverflow.com/a/8056313
// - https://bugzilla.mozilla.org/show_bug.cgi?id=998076 // - https://bugzilla.mozilla.org/show_bug.cgi?id=998076
// https://www.reddit.com/r/uBlockOrigin/comments/cpxm1v/
// User-supplied resources may already be base64 encoded.
toURL(fctxt, asDataURI = false) { toURL(fctxt, asDataURI = false) {
if ( if (
@ -219,7 +221,11 @@ const RedirectEntry = class {
return `data:${mime},`; return `data:${mime},`;
} }
if ( this.data.startsWith('data:') === false ) { if ( this.data.startsWith('data:') === false ) {
this.data = `data:${this.mime};base64,${btoa(this.data)}`; if ( this.mime.indexOf(';') === -1 ) {
this.data = `data:${this.mime};base64,${btoa(this.data)}`;
} else {
this.data = `data:${this.mime},${this.data}`;
}
} }
return this.data; return this.data;
} }