diff --git a/src/browserExt/contentTypeHandler.js b/src/browserExt/contentTypeHandler.js index 1d9bafd9c..e3372ccd1 100644 --- a/src/browserExt/contentTypeHandler.js +++ b/src/browserExt/contentTypeHandler.js @@ -48,6 +48,7 @@ Zotero.ContentTypeHandler = { mv3CSLWhitelistRegexp: { "https://www.zotero.org/styles/\\1": /https?:\/\/(?:www\.)zotero\.org\/styles\/?#importConfirm=(.*)$/, "https://raw.githubusercontent.com/\\1/\\2": /https?:\/\/github\.com\/([^/]*\/[^/]*)\/[^/]*\/([^.]*.csl)#importConfirm$/, + "https://gitee.com/\\1/raw/\\2": /https?:\/\/gitee\.com\/([^/]+\/[^/]+)\/blob\/(.+\.csl)#importConfirm$/ }, ignoreURL: new Set(), @@ -137,15 +138,14 @@ Zotero.ContentTypeHandler = { }, _isImportableStyle: function (url, contentType) { - const URI = new URL(url); // Offer to install CSL by Content-Type if (Zotero.ContentTypeHandler.cslContentTypes.has(contentType)) { return true; } // Offer to install CSL if URL path ends with .csl and host is allowed - else if (URI.pathname.match(/\.csl$/)) { + else if (/\.csl$/i.test(url)) { let hosts = Zotero.Prefs.get('allowedCSLExtensionHosts'); - if (Array.isArray(hosts) && hosts.includes(URI.hostname)) { + if (Array.isArray(hosts) && hosts.some(host => new RegExp(host).test(url))) { return true; } } diff --git a/src/browserExt/styleInterceptRules.json b/src/browserExt/styleInterceptRules.json index d87f62df4..778b4246d 100644 --- a/src/browserExt/styleInterceptRules.json +++ b/src/browserExt/styleInterceptRules.json @@ -26,5 +26,19 @@ "regexFilter": "^https://raw\\.githubusercontent\\.com/([^/]*/[^/]*)/([^/]*/[^#?]+.csl)$", "resourceTypes": ["main_frame"] } + }, + { + "id": 3, + "priority": 1, + "action": { + "type": "redirect", + "redirect": { + "regexSubstitution": "https://gitee.com/\\1/blob/\\2#importConfirm" + } + }, + "condition": { + "regexFilter": "^https://gitee\\.com/([^/]+/[^/]+)/raw/(.+\\.csl)$", + "resourceTypes": ["main_frame"] + } } ] \ No newline at end of file diff --git a/src/common/zotero.js b/src/common/zotero.js index e71a4f379..d0c4e1e66 100644 --- a/src/common/zotero.js +++ b/src/common/zotero.js @@ -374,7 +374,7 @@ Zotero.Prefs = new function() { "connector.url": 'http://127.0.0.1:23119/', "capitalizeTitles": false, "interceptKnownFileTypes": true, - "allowedCSLExtensionHosts": ["raw.githubusercontent.com", "gitee.com"], + "allowedCSLExtensionHosts": ["^https://raw\\.githubusercontent\\.com/", "^https://gitee\\.com/.+/raw/"], "allowedInterceptHosts": [], "firstUse": true, "firstSaveToServer": true,