Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "1.3.0-beta.4",
"version": "1.3.0",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"author": "CodFrm",
"license": "GPLv3",
Expand Down
2 changes: 1 addition & 1 deletion src/app/repo/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ResourceDAO extends Repo<Resource> {
}

// CompiledResource结构变更时,建议修改 CompiledResourceNamespace 以删除旧Cache
export const CompiledResourceNamespace = "a51b9167-fdde-467a-a86f-75e5636adda2";
export const CompiledResourceNamespace = "57d79c56-231a-42d3-b6e3-d2004ba0866f";

export class CompiledResourceDAO extends Repo<CompiledResource> {
constructor() {
Expand Down
10 changes: 7 additions & 3 deletions src/app/service/content/script_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/pkg/utils/match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
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"]);
});
});
8 changes: 6 additions & 2 deletions src/pkg/utils/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export class UrlMatch<T> {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/utils/url_matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function checkUrlMatch(s: string) {
}

const globSplit = (text: string) => {
text = text.replace(/\*{2,}/g, "*"); // api定义的 glob * 是等价于 glob **
text = text.replace(/\*(\?+)/g, "$1*"); // "*????" 改成 "????*",避免 backward 处理
text = text.replace(/\*{2,}/g, "*"); // api定义的 glob * 是等价于 glob **
return text.split(/([*?])/g);
};

Expand Down
Loading