gobwas / glob

Go glob
MIT License
948 stars 63 forks source link

[BUG] Asterisk and intersecting fragments not working as expected #61

Open naughtyfox opened 1 year ago

naughtyfox commented 1 year ago

HI, all! I got the following code:

package main

import (
    "log"

    "github.com/gobwas/glob"
)

func main() {
    pattern := "start*art"
    gl := glob.MustCompile(pattern)

    s := "start"
    log.Printf("Result: %v", gl.Match(s)) 
}

Which results in:

$ ./main
2023/08/01 16:20:08 Result: true

I expect it to be false. Is this a bug?

naughtyfox commented 1 year ago

I checked it against filepath.Match function:

package main

import (
    "log"
    "path/filepath"

    "github.com/gobwas/glob"
)

func main() {
    pattern := "start*art"
    gl := glob.MustCompile(pattern)

    s := "start"
    log.Printf("glob result: %v", gl.Match(s))

    matched, err := filepath.Match(pattern, s)
    if err != nil {
        log.Fatalf("failed to match: %v", err)
    }

    log.Printf("filepath.Match result: %v", matched)
}

Result:

$ ./main
2023/08/01 16:58:00 glob result: true
2023/08/01 16:58:00 filepath.Match result: false

It seems like a bug...