Skip to content

Commit

Permalink
Fix: escape special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 committed Nov 19, 2024
1 parent f4bb557 commit 0723a87
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/fetch-delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function matchGlob(pattern, string) {
if (!pattern.includes("*")) {
return pattern === string;
}
return new RegExp(`^${pattern.replace(/\*/g, ".*")}$`).test(string);
// compile a glob pattern to a regular expression, also escape special characters
const rx = new RegExp(`^${pattern.replace(/[-/\\^$+?.()|[\]{}]/g, "\\$&").replace(/\*/g, ".*")}$`);
return rx.test(string);
}

export async function fetchDelay(url, cb) {
Expand Down

0 comments on commit 0723a87

Please sign in to comment.