fix: align directory wildcard matching

This commit is contained in:
OpenClaw Agent
2026-09-21 17:05:58 +08:00
parent c0f3b94c30
commit 7791b3e7d3
2 changed files with 75 additions and 21 deletions
+31 -10
View File
@@ -108,22 +108,43 @@ func matchPath(pattern, path string) bool {
return false
}
for i, p := range pp {
if p == "*" {
return true
}
if p == "?" {
if ps[i] == "" {
return false
}
continue
}
if p != ps[i] {
if !matchSegment(p, ps[i]) {
return false
}
}
return true
}
func matchSegment(pattern, value string) bool {
p := []rune(pattern)
v := []rune(value)
dp := make([][]bool, len(p)+1)
for i := range dp {
dp[i] = make([]bool, len(v)+1)
}
dp[0][0] = true
for i := 1; i <= len(p); i++ {
if p[i-1] == '*' {
dp[i][0] = dp[i-1][0]
}
}
for i := 1; i <= len(p); i++ {
for j := 1; j <= len(v); j++ {
switch p[i-1] {
case '*':
dp[i][j] = dp[i-1][j] || dp[i][j-1]
case '?':
dp[i][j] = dp[i-1][j-1]
default:
dp[i][j] = dp[i-1][j-1] && p[i-1] == v[j-1]
}
}
}
return dp[len(p)][len(v)]
}
func MatchPath(pattern, path string) bool { return matchPath(pattern, path) }
func NewToken() string {
b := make([]byte, 32)
if _, e := rand.Read(b); e != nil {