gobwas / glob

Go glob
MIT License
948 stars 63 forks source link

Unexpected result matching windows paths #35

Open nirekin opened 5 years ago

nirekin commented 5 years ago

I am trying to match a windows path but the given result is not the expected one:

g := glob.MustCompile("C:\\p1\\p2\\templateTarget[12].yaml")
g.Match("C:\\p1\\p2\\templateTarget1.yaml") // false

I find a workaround replacing all the \\ by / but it's kind of annoying...

g := glob.MustCompile("C:/p1/p2/templateTarget[12].yaml")
g.Match("C:/p1/p2/templateTarget1.yaml") // true
gobwas commented 5 years ago

Hi @nirekin, there is a QuoteMeta() call for such cases. Ping me if it does not help :)

nirekin commented 5 years ago

Hi @gobwas,

I have tried to use it but I cant figure how it could be helpful in that case. Quoting the glob pattern meta characters has no effects, not good nor bad...

g := glob.MustCompile(glob.QuoteMeta("C:\\p1\\p2\\templateTarget[12].yaml"))
g.Match("C:\\p1\\p2\\templateTarget1.yaml") // false

Do you have any additional hint or example?