gobwas / glob

Go glob
MIT License
948 stars 63 forks source link

Strange, incorrect question mark behaviour. #18

Closed donatj closed 7 years ago

donatj commented 7 years ago

It would appear there is an error in how question mark is handled such that the full string is no longer matched against.

Here is a bug I ran into in production

package main

import (
    "log"

    "github.com/gobwas/glob"
)

func main() {
    x := glob.MustCompile("sta")
    log.Println(x.Match("stagnation"))

    x2 := glob.MustCompile("sta*")
    log.Println(x2.Match("stagnation"))

    x3 := glob.MustCompile("sta?")
    log.Println(x3.Match("stagnation"))

    x4 := glob.MustCompile("sta?n")
    log.Println(x4.Match("stagnation"))
}

outputs

2016/10/19 17:13:44 false                                                          
2016/10/19 17:13:44 true                                                           
2016/10/19 17:13:44 true                                                           
2016/10/19 17:13:44 true 

but I would expect

2016/10/19 17:13:44 false                                                          
2016/10/19 17:13:44 true                                                           
2016/10/19 17:13:44 false                                                           
2016/10/19 17:13:44 false 

Which is how glob is handled in bash and zsh:

screen shot 2016-10-19 at 5 09 57 pm

gobwas commented 7 years ago

Hi @donatj! Nice catch! Sorry. Fix will be available in 5 minutes ;-)

gobwas commented 7 years ago

@donatj fixed in v0.2.1 tag and in master.

donatj commented 7 years ago

Awesome! Thank you!

gobwas commented 7 years ago

@donatj thank you! 🍻