fix 修复 路由守卫白名单通配符正则覆盖问题

This commit is contained in:
QianRj 2025-02-06 20:20:40 +08:00
parent 904ee32b24
commit fb7bca27eb

View File

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