From 6c73bd78f47090259fc5bb46f906f5ecfbad1e6f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 16 Aug 2019 13:43:41 -0400 Subject: [PATCH] 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. --- src/js/cachestorage.js | 12 ++++++------ src/js/redirect-engine.js | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/js/cachestorage.js b/src/js/cachestorage.js index 2f9b16968..cb0f3690d 100644 --- a/src/js/cachestorage.js +++ b/src/js/cachestorage.js @@ -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 = ( ) => { diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index df1081485..c2e053a5c 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -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; }