Skip to content

Commit 2155d9f

Browse files
JavaLionLigitee-org
authored andcommitted
!181 fix 修复 路由守卫白名单通配符正则覆盖问题
Merge pull request !181 from QianRj/dev
2 parents 904ee32 + fb7bca2 commit 2155d9f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/utils/validate.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
* @returns {Boolean}
66
*/
77
export function isPathMatch(pattern: string, path: string) {
8-
const regexPattern = pattern.replace(/\//g, '\\/').replace(/\*\*/g, '.*').replace(/\*/g, '[^\\/]*')
9-
const regex = new RegExp(`^${regexPattern}$`)
10-
return regex.test(path)
8+
const regexPattern = pattern
9+
.replace(/\//g, '\\/')
10+
.replace(/\*\*/g, '__DOUBLE_STAR__')
11+
.replace(/\*/g, '[^\\/]*')
12+
.replace(/__DOUBLE_STAR__/g, '.*');
13+
const regex = new RegExp(`^${regexPattern}$`);
14+
return regex.test(path);
1115
}
1216

1317
/**

0 commit comments

Comments
 (0)