diff --git a/background/storage.js b/background/storage.js index b57cdf62..55c47590 100644 --- a/background/storage.js +++ b/background/storage.js @@ -174,6 +174,7 @@ function getStyles(options) { return dbExec('getAll').then(event => { cachedStyles.list = event.target.result || []; + cachedStyles.list.forEach(fixUsoMd5Issue); cachedStyles.byId.clear(); for (const style of cachedStyles.list) { cachedStyles.byId.set(style.id, style); @@ -264,6 +265,14 @@ function filterStyles({ } +// The md5Url provided by USO includes a duplicate "update" subdomain (see #523), +// This fixes any already installed styles containing this error +function fixUsoMd5Issue(style) { + if (style && style.md5Url && style.md5Url.includes('update.update.userstyles')) { + style.md5Url = style.md5Url.replace('update.update.userstyles', 'update.userstyles'); + } +} + function filterStylesInternal({ // js engines don't like big functions (V8 often deoptimized the original filterStyles) // it also makes sense to extract the less frequently executed code @@ -350,6 +359,8 @@ function saveStyle(style) { let existed; let codeIsUpdated; + fixUsoMd5Issue(style); + return maybeCalcDigest() .then(maybeImportFix) .then(decide); diff --git a/content/install-hook-userstyles.js b/content/install-hook-userstyles.js index d26a88af..7ebdbd22 100644 --- a/content/install-hook-userstyles.js +++ b/content/install-hook-userstyles.js @@ -238,6 +238,14 @@ }); } + // USO providing md5Url as "https://update.update.userstyles.org/#####.md5" + // instead of "https://update.userstyles.org/#####.md5" + function tryFixMd5(style) { + if (style && style.md5Url && style.md5Url.includes('update.update')) { + style.md5Url = style.md5Url.replace('update.update', 'update'); + } + return style; + } function getStyleJson() { return getResource(getStyleURL(), {responseType: 'json'}) @@ -256,6 +264,7 @@ }); })); }) + .then(tryFixMd5) .catch(() => null); }