From 801d6500b04f31663fad496c3dc8d61337dfc6ff Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 29 Feb 2024 13:28:04 -0500 Subject: [PATCH] Fix idbStorage.keys() Related commit: https://github.com/gorhill/uBlock/commit/d4efaf020b --- src/js/assets.js | 2 +- src/js/cachestorage.js | 7 ++++--- src/js/start.js | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/js/assets.js b/src/js/assets.js index 749fb7802..0eb8ef3c4 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -790,7 +790,7 @@ async function assetCacheRemove(pattern, options = {}) { } if ( options.janitor && pattern instanceof RegExp ) { const re = new RegExp( - pattern.source.replace(/^\^/, 'cache\/'), + pattern.source.replace(/^\^/, '^cache\\/'), pattern.flags ); const keys = await cacheStorage.keys(re); diff --git a/src/js/cachestorage.js b/src/js/cachestorage.js index f1e940df7..f8b406c95 100644 --- a/src/js/cachestorage.js +++ b/src/js/cachestorage.js @@ -546,7 +546,7 @@ const idbStorage = (( ) => { }); }; - const getAllKeys = async function() { + const getAllKeys = async function(regex) { const db = await getDb(); if ( db === null ) { return []; } return new Promise(resolve => { @@ -562,6 +562,7 @@ const idbStorage = (( ) => { req.onsuccess = ev => { const cursor = ev.target && ev.target.result; if ( !cursor ) { return; } + if ( regex && regex.test(cursor.key) === false ) { return; } keys.push(cursor.key); cursor.continue(); }; @@ -685,8 +686,8 @@ const idbStorage = (( ) => { return setEntries(bin); }, - keys() { - return getAllKeys(); + keys(...args) { + return getAllKeys(...args); }, remove(...args) { diff --git a/src/js/start.js b/src/js/start.js index 2bda75c1f..a3052cc08 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -232,8 +232,7 @@ const onUserSettingsReady = fetched => { fetched.importedLists.length === 0 && fetched.externalLists !== '' ) { - fetched.importedLists = - fetched.externalLists.trim().split(/[\n\r]+/); + fetched.importedLists = fetched.externalLists.trim().split(/[\n\r]+/); } fromFetch(µb.userSettings, fetched);