gobwas/glob

Asterisk at beginning matches like double-asterisk

kamermans opened this issue · 2 comments

Thanks for the library, great work!

Please consider this example:

g := glob.MustCompile("*.github.com")
fmt.Println(g.Match("api.github.com"))     // true
fmt.Println(g.Match("foo.api.github.com")) // true, but should be false

g = glob.MustCompile("**.github.com")
fmt.Println(g.Match("api.github.com"))     // true
fmt.Println(g.Match("foo.api.github.com")) // true

In my understanding (and use case), *.github.com should not match foo.api.github.com since the single asterisk should only match one component in the domain (api). If I wanted to match multiple components, like foo.api, I would use **.github.com.

calmh commented

(Not package author, just interested bystander.)

You didn’t set the component delimiter, which is by default a slash (for file paths). Viewing your examples as file names the behavior is correct.

Nevermind, I am just blind apparently - the second argument to MustCompile() is the separator. Everything works as documented, thanks @calmh!