Skip to content

Commit 0723a87

Browse files
committed
Fix: escape special chars
1 parent f4bb557 commit 0723a87

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib/fetch-delay.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function matchGlob(pattern, string) {
3434
if (!pattern.includes("*")) {
3535
return pattern === string;
3636
}
37-
return new RegExp(`^${pattern.replace(/\*/g, ".*")}$`).test(string);
37+
// compile a glob pattern to a regular expression, also escape special characters
38+
const rx = new RegExp(`^${pattern.replace(/[-/\\^$+?.()|[\]{}]/g, "\\$&").replace(/\*/g, ".*")}$`);
39+
return rx.test(string);
3840
}
3941

4042
export async function fetchDelay(url, cb) {

0 commit comments

Comments
 (0)