Skip to content

Commit dc024af

Browse files
committed
🐛 修复一些特殊匹配
1 parent bd8d3cd commit dc024af

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/pkg/utils/match.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ describe("UrlMatch-search", () => {
8282
expect(url.match("https://www.example.com/path/foo/bar/baz")).toEqual(["ok1"]);
8383
expect(url.match("https://www.example.com/path2/foo")).toEqual([]);
8484
});
85+
it("http*", () => {
86+
const url = new UrlMatch<string>();
87+
url.add("http*", "ok1");
88+
expect(url.match("http://www.example.com")).toEqual(["ok1"]);
89+
expect(url.match("https://www.example.com")).toEqual(["ok1"]);
90+
});
8591
});
8692

8793
describe("UrlMatch-port1", () => {
@@ -141,20 +147,23 @@ describe("dealPatternMatches", () => {
141147
"*://api.*.*.example.com/*",
142148
"*://*example.com/*",
143149
"*.example.com/path/*",
150+
"http*",
144151
]);
145152
expect(matches.patternResult).toEqual([
146153
"*://*/*",
147154
"*://*.example.com/*",
148155
"*://*.example.com/*",
149156
"*://example.com/*",
150157
"*://*.example.com/path/*",
158+
"*://*/*",
151159
]);
152160
expect(matches.result).toEqual([
153161
"*://www.example.com*",
154162
"*://api.*.example.com/*",
155163
"*://api.*.*.example.com/*",
156164
"*://*example.com/*",
157165
"*.example.com/path/*",
166+
"http*",
158167
]);
159168
});
160169
it("特殊情况-exclude", () => {
@@ -246,11 +255,16 @@ describe("parsePatternMatchesURL", () => {
246255
path: "*",
247256
});
248257
matches = parsePatternMatchesURL("*.example.com/path/*");
249-
console.log(matches);
250258
expect(matches).toEqual({
251259
scheme: "*",
252260
host: "*.example.com",
253261
path: "path/*",
254262
});
263+
matches = parsePatternMatchesURL("http*");
264+
expect(matches).toEqual({
265+
scheme: "*",
266+
host: "*",
267+
path: "*",
268+
});
255269
});
256270
});

src/pkg/utils/match.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class Match<T> {
3636
// 处理一些特殊情况
3737
switch (url) {
3838
case "*":
39+
case "http*":
3940
return {
4041
scheme: "*",
4142
host: "*",

0 commit comments

Comments
 (0)