diff --git a/package.json b/package.json index dfec7228..f4dc741f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptcat", - "version": "0.16.0-beta", + "version": "0.16.0-beta.1", "description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!", "author": "CodFrm", "license": "GPLv3", diff --git a/src/pkg/utils/match.test.ts b/src/pkg/utils/match.test.ts index 89b4944e..0313c246 100644 --- a/src/pkg/utils/match.test.ts +++ b/src/pkg/utils/match.test.ts @@ -116,6 +116,7 @@ describe("UrlMatch-port2", () => { url.add("http://test.list.ggnb.top:80/search", "ok1"); url.add("http://test.list.ggnb.top*/search", "ok2"); url.add("http://test.list.ggnb.top:*/search", "ok3"); + url.add("http://localhost:3000/", "ok4"); it("match1", () => { expect(url.match("http://test.list.ggnb.top:80/search")).toEqual([ "ok1", @@ -123,7 +124,6 @@ describe("UrlMatch-port2", () => { "ok3", ]); expect(url.match("http://test.list.ggnb.top:81/search")).toEqual([ - "ok1", "ok2", "ok3", ]); @@ -133,6 +133,10 @@ describe("UrlMatch-port2", () => { "ok3", ]); }); + it("case2", () => { + expect(url.match("http://localhost:3000/")).toEqual(["ok4"]); + expect(url.match("http://localhost:8000/")).toEqual([]); + }); }); describe("特殊情况", () => { diff --git a/src/pkg/utils/match.ts b/src/pkg/utils/match.ts index d74bab67..fe774b7a 100644 --- a/src/pkg/utils/match.ts +++ b/src/pkg/utils/match.ts @@ -53,7 +53,9 @@ export default class Match { pos = -1; } else if (u.host.endsWith("*")) { // 处理*结尾 - u.host = u.host.substring(0, u.host.length - 1); + if (!u.host.endsWith(":*")) { + u.host = u.host.substring(0, u.host.length - 1); + } } else if (pos !== -1 && pos !== 0) { return ""; } @@ -75,7 +77,12 @@ export default class Match { if (pos2 === -1) { u.host = `${u.host}(:\\d+)?`; } else { - u.host = `${u.host.substring(0, pos2)}(:\\d+)?`; + const port = u.host.substring(pos2 + 1); + if (port === "*") { + u.host = `${u.host.substring(0, pos2)}(:\\d+)?`; + } else { + u.host = `${u.host.substring(0, pos2)}(:${port})?`; + } } let re = `^${u.scheme}://${u.host}`; if (u.path === "/") {