glob
glob copied to clipboard
[BUG] Brace expansion with exactly 2 alternatives fails to match when 1, 3, or 4+ alternatives work correctly
Summary
There appears to be a bug in the brace expansion logic when a pattern contains exactly 2 alternatives in braces {option1,option2}. Patterns with 1, 3, or 4+ alternatives work correctly, but patterns with exactly 2 alternatives fail to match even when the logic should succeed.
Reproduction Steps
package main
import (
"fmt"
"github.com/gobwas/glob"
)
func main() {
input := "playground/daxing/generated/dev.yaml"
// Test patterns with different numbers of brace alternatives
testPatterns := []string{
"{**/daxing}/**/*dev*.yaml", // 1 option - WORKS
"{**/daxing,daxing}/**/*dev*.yaml", // 2 options - FAILS
"{**/daxing,daxing,x}/**/*dev*.yaml", // 3 options - WORKS
"{**/daxing,daxing,x,y}/**/*dev*.yaml", // 4 options - WORKS
}
for _, pattern := range testPatterns {
g, _ := glob.Compile(pattern)
result := g.Match(input)
fmt.Printf("Pattern %s matches: %v\n", pattern, result)
}
}
Expected Behavior
All patterns should return true since:
-
**/daxingmatchesplayground/daxingin the input path -
/**/*dev*.yamlmatches/generated/dev.yamlportion
Actual Behavior
Pattern {**/daxing}/**/*dev*.yaml matches: true
Pattern {**/daxing,daxing}/**/*dev*.yaml matches: false ← BUG
Pattern {**/daxing,daxing,x}/**/*dev*.yaml matches: true
Pattern {**/daxing,daxing,x,y}/**/*dev*.yaml matches: true
Analysis
The issue seems specific to brace expansions with exactly 2 alternatives. The pattern {**/daxing,daxing} should expand to two possibilities and match if either one matches, but this logic appears to fail.
Environment
- Go version: 1.24.1
- gobwas/glob version: v0.2.3
Workaround
Adding a dummy third option makes the pattern work:
"{**/daxing,daxing,dummy}/**/*dev*.yaml" // Returns true