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

This commit is contained in:
RuoYi
2026-04-16 13:43:39 +08:00
parent b33d43840e
commit 613d0bbc94
+6 -1
View File
@@ -5,7 +5,12 @@
* @returns {Boolean} * @returns {Boolean}
*/ */
export function isPathMatch(pattern, path) { export function isPathMatch(pattern, path) {
const regexPattern = pattern.replace(/\//g, '\\/').replace(/\*\*/g, '.*').replace(/\*/g, '[^\\/]*') const regexPattern = pattern
.replace(/([.+^${}()|\[\]\\])/g, '\\$1')
.replace(/\*\*/g, '__DOUBLE_STAR__')
.replace(/\*/g, '[^/]*')
.replace(/__DOUBLE_STAR__/g, '.*')
.replace(/\?/g, '[^/]')
const regex = new RegExp(`^${regexPattern}$`) const regex = new RegExp(`^${regexPattern}$`)
return regex.test(path) return regex.test(path)
} }