update 优化 白名单支持对通配符路径匹配

This commit is contained in:
疯狂的狮子Li 2026-04-16 16:10:16 +08:00
parent 0a5c72988a
commit ffcb15ba96

View File

@ -6,9 +6,10 @@
*/
export function isPathMatch(pattern: string, path: string) {
const regexPattern = pattern
.replace(/\//g, '\\/')
.replace(/([.+^${}()|\[\]\\])/g, '\\$1')
.replace(/\*\*/g, '__DOUBLE_STAR__')
.replace(/\*/g, '[^\\/]*')
.replace(/\?/g, '[^\\/]')
.replace(/__DOUBLE_STAR__/g, '.*');
const regex = new RegExp(`^${regexPattern}$`);
return regex.test(path);