update 优化 白名单支持对通配符路径匹配
This commit is contained in:
@@ -6,9 +6,10 @@
|
|||||||
*/
|
*/
|
||||||
export function isPathMatch(pattern: string, path: string) {
|
export function isPathMatch(pattern: string, path: string) {
|
||||||
const regexPattern = pattern
|
const regexPattern = pattern
|
||||||
.replace(/\//g, '\\/')
|
.replace(/([.+^${}()|\[\]\\])/g, '\\$1')
|
||||||
.replace(/\*\*/g, '__DOUBLE_STAR__')
|
.replace(/\*\*/g, '__DOUBLE_STAR__')
|
||||||
.replace(/\*/g, '[^\\/]*')
|
.replace(/\*/g, '[^\\/]*')
|
||||||
|
.replace(/\?/g, '[^\\/]')
|
||||||
.replace(/__DOUBLE_STAR__/g, '.*');
|
.replace(/__DOUBLE_STAR__/g, '.*');
|
||||||
const regex = new RegExp(`^${regexPattern}$`);
|
const regex = new RegExp(`^${regexPattern}$`);
|
||||||
return regex.test(path);
|
return regex.test(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user