diff --git a/package.json b/package.json index fb3929cee..0f11d120e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptcat", - "version": "1.3.0-beta.4", + "version": "1.3.0", "description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!", "author": "CodFrm", "license": "GPLv3", diff --git a/src/app/repo/resource.ts b/src/app/repo/resource.ts index 5aa0889b2..e9eff5aa4 100644 --- a/src/app/repo/resource.ts +++ b/src/app/repo/resource.ts @@ -64,7 +64,7 @@ export class ResourceDAO extends Repo { } // CompiledResource结构变更时,建议修改 CompiledResourceNamespace 以删除旧Cache -export const CompiledResourceNamespace = "a51b9167-fdde-467a-a86f-75e5636adda2"; +export const CompiledResourceNamespace = "57d79c56-231a-42d3-b6e3-d2004ba0866f"; export class CompiledResourceDAO extends Repo { constructor() { diff --git a/src/app/service/content/script_executor.ts b/src/app/service/content/script_executor.ts index c231213f6..1d4715b6d 100644 --- a/src/app/service/content/script_executor.ts +++ b/src/app/service/content/script_executor.ts @@ -106,9 +106,13 @@ export class ScriptExecutor { // "@exclude /REGEX/" 的情况下,MV3 UserScripts API 基础匹配范围不会扩大,然后在 earlyScript 把符合 REGEX 的匹配除去 // (Any @exclude = true -> 除去) // 注:如果一早已被除排,根本不会被 MV3 UserScripts API 注入。所以只考虑排除「多余的匹配」。(略过注入) - if (isUrlExcluded(window.location.href, detail.scriptInfo.scriptUrlPatterns)) { - // 「多余的匹配」-> 略过注入 - return; + try { + if (isUrlExcluded(window.location.href, detail.scriptInfo.scriptUrlPatterns)) { + // 「多余的匹配」-> 略过注入 + return; + } + } catch (e) { + console.warn("Unexpected match error", e); } } this.execEarlyScript(scriptFlag, detail.scriptInfo, envInfo); diff --git a/src/pkg/utils/match.test.ts b/src/pkg/utils/match.test.ts index eeec35dac..5abf7920d 100644 --- a/src/pkg/utils/match.test.ts +++ b/src/pkg/utils/match.test.ts @@ -889,3 +889,13 @@ describe.concurrent("@include /REGEX/", () => { expect(isUrlIncluded("http://www.hlample.com/", url.rulesMap.get("ok1")!)).toEqual(false); }); }); + +describe.concurrent("invalid or unsupported glob #1271", () => { + const url = new UrlMatch(); + url.addInclude("*://*?*", "ok1"); + url.addInclude("*://*?page*", "ok2"); + it.concurrent("include *://*?*", () => { + expect(url.urlMatch("http://www.example.com/?a=1")).toEqual(["ok1"]); + expect(url.urlMatch("http://www.example.com/?page=1")).toEqual(["ok1", "ok2"]); + }); +}); diff --git a/src/pkg/utils/match.ts b/src/pkg/utils/match.ts index a94da8d81..81f3a42dd 100644 --- a/src/pkg/utils/match.ts +++ b/src/pkg/utils/match.ts @@ -18,8 +18,12 @@ export class UrlMatch { if (cacheMap.has(url)) return cacheMap.get(url) as T[]; const res: T[] = []; for (const [uuid, rules] of this.rulesMap) { - if (isUrlIncluded(url, rules)) { - res.push(uuid); + try { + if (isUrlIncluded(url, rules)) { + res.push(uuid); + } + } catch (e) { + console.warn("Unexpected match error", e); } } const sorter = this.sorter; diff --git a/src/pkg/utils/url_matcher.ts b/src/pkg/utils/url_matcher.ts index 08f5f37f2..e2fb6e218 100644 --- a/src/pkg/utils/url_matcher.ts +++ b/src/pkg/utils/url_matcher.ts @@ -57,9 +57,15 @@ export function checkUrlMatch(s: string) { } const globSplit = (text: string) => { - text = text.replace(/\*{2,}/g, "*"); // api定义的 glob * 是等价于 glob ** - text = text.replace(/\*(\?+)/g, "$1*"); // "*????" 改成 "????*",避免 backward 处理 - return text.split(/([*?])/g); + const split = text.split(/([*?]{2,})/g); + for (let i = 1; i < split.length; i += 2) { + // "*????" 改成 "????*",避免 backward 处理 + // api定义的 glob * 是等价于 glob ** + const p = split[i]; // **??**??** + const q = p.replace(/\*/g, ""); // ???? + if (p !== q) split[i] = `${q}*`; // ????* + } + return split.join("").split(/([*?])/g); }; export const extractUrlPatterns = (lines: string[]): URLRuleEntry[] => {