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

View File

@ -201,6 +201,8 @@ const RedirectEntry = class {
// cause leakage of extension id. See:
// - https://stackoverflow.com/a/8056313
// - 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) {
if (
@ -219,7 +221,11 @@ const RedirectEntry = class {
return `data:${mime},`;
}
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;
}