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

Merge pull request !181 from QianRj/dev
This commit is contained in:
疯狂的狮子Li 2025-02-07 03:23:51 +00:00 committed by Gitee
commit 2155d9f4b0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -5,9 +5,13 @@
* @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)
const regexPattern = pattern
.replace(/\//g, '\\/')
.replace(/\*\*/g, '__DOUBLE_STAR__')
.replace(/\*/g, '[^\\/]*')
.replace(/__DOUBLE_STAR__/g, '.*');
const regex = new RegExp(`^${regexPattern}$`);
return regex.test(path);
}
/**