Skip to content

Commit ccd4085

Browse files
committed
πŸ› ε€„η†δΈ€δΊ›ζ­£εˆ™εŒΉι…ηš„ζƒ…ε†΅
1 parent d32793e commit ccd4085

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

β€Žsrc/pkg/utils/match.test.tsβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,11 @@ describe("parsePatternMatchesURL", () => {
266266
host: "*",
267267
path: "*",
268268
});
269+
matches = parsePatternMatchesURL("/^.*?://.*?.example.com.*?$/");
270+
expect(matches).toEqual({
271+
scheme: "*",
272+
host: "*",
273+
path: "*",
274+
});
269275
});
270276
});

β€Žsrc/pkg/utils/match.tsβ€Ž

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ export default class Match<T> {
108108
return `${re.replace(/\//g, "/")}$`;
109109
}
110110

111-
public add(url: string, val: T) {
112-
const re = this.compileRe(url);
113-
if (!re) {
114-
throw new Error(`invalid url: ${url}`);
115-
}
111+
addRegex(re: string, val: T) {
116112
let rule = this.rule.get(re);
117113
if (!rule) {
118114
rule = [];
@@ -123,6 +119,19 @@ export default class Match<T> {
123119
this.delCache();
124120
}
125121

122+
public add(url: string, val: T) {
123+
// εˆ€ζ–­ζ˜―δΈζ˜―δΈ€δΈͺζ­£εˆ™
124+
if (url.startsWith("/^") || url.endsWith("$/")) {
125+
this.addRegex(url, val);
126+
}
127+
const re = this.compileRe(url);
128+
if (!re) {
129+
console.warn("bad match rule", { url, val });
130+
return;
131+
}
132+
this.addRegex(re, val);
133+
}
134+
126135
public match(url: string): T[] {
127136
let ret = this.cache.get(url);
128137
if (ret) {
@@ -231,6 +240,14 @@ export function parsePatternMatchesURL(
231240
exclude?: boolean;
232241
}
233242
): PatternMatchesUrl | undefined {
243+
// ε¦‚ζžœζ˜―ζ­£εˆ™οΌŒε€„η†ζˆι€šι…
244+
if (url.startsWith("/^") || url.endsWith("$/")) {
245+
return {
246+
scheme: "*",
247+
host: "*",
248+
path: "*",
249+
};
250+
}
234251
let result: PatternMatchesUrl | undefined;
235252
const match = /^(.+?):\/\/(.*?)(\/(.*?)(\?.*?|)|)$/.exec(url);
236253
if (match) {

0 commit comments

Comments
Β (0)