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

This commit is contained in:
疯狂的狮子Li
2024-12-04 11:42:07 +08:00
parent 00f7ab34ef
commit fd01b5a61f
2 changed files with 19 additions and 3 deletions

View File

@ -1,3 +1,15 @@
/**
* 路径匹配器
* @param {string} pattern
* @param {string} path
* @returns {Boolean}
*/
export function isPathMatch(pattern: string, path: string) {
const regexPattern = pattern.replace(/\//g, '\\/').replace(/\*\*/g, '.*').replace(/\*/g, '[^\\/]*')
const regex = new RegExp(`^${regexPattern}$`)
return regex.test(path)
}
/**
* 判断url是否是http或https
* @returns {Boolean}