Skip to content

Commit 2e378c3

Browse files
committed
🐛 修复@match 端口匹配错误 #244
1 parent c04a829 commit 2e378c3

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.16.0-beta",
3+
"version": "0.16.0-beta.1",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",

‎src/pkg/utils/match.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ describe("UrlMatch-port2", () => {
116116
url.add("http://test.list.ggnb.top:80/search", "ok1");
117117
url.add("http://test.list.ggnb.top*/search", "ok2");
118118
url.add("http://test.list.ggnb.top:*/search", "ok3");
119+
url.add("http://localhost:3000/", "ok4");
119120
it("match1", () => {
120121
expect(url.match("http://test.list.ggnb.top:80/search")).toEqual([
121122
"ok1",
122123
"ok2",
123124
"ok3",
124125
]);
125126
expect(url.match("http://test.list.ggnb.top:81/search")).toEqual([
126-
"ok1",
127127
"ok2",
128128
"ok3",
129129
]);
@@ -133,6 +133,10 @@ describe("UrlMatch-port2", () => {
133133
"ok3",
134134
]);
135135
});
136+
it("case2", () => {
137+
expect(url.match("http://localhost:3000/")).toEqual(["ok4"]);
138+
expect(url.match("http://localhost:8000/")).toEqual([]);
139+
});
136140
});
137141

138142
describe("特殊情况", () => {

‎src/pkg/utils/match.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export default class Match<T> {
5353
pos = -1;
5454
} else if (u.host.endsWith("*")) {
5555
// 处理*结尾
56-
u.host = u.host.substring(0, u.host.length - 1);
56+
if (!u.host.endsWith(":*")) {
57+
u.host = u.host.substring(0, u.host.length - 1);
58+
}
5759
} else if (pos !== -1 && pos !== 0) {
5860
return "";
5961
}
@@ -75,7 +77,12 @@ export default class Match<T> {
7577
if (pos2 === -1) {
7678
u.host = `${u.host}(:\\d+)?`;
7779
} else {
78-
u.host = `${u.host.substring(0, pos2)}(:\\d+)?`;
80+
const port = u.host.substring(pos2 + 1);
81+
if (port === "*") {
82+
u.host = `${u.host.substring(0, pos2)}(:\\d+)?`;
83+
} else {
84+
u.host = `${u.host.substring(0, pos2)}(:${port})?`;
85+
}
7986
}
8087
let re = `^${u.scheme}://${u.host}`;
8188
if (u.path === "/") {

0 commit comments

Comments
 (0)