Skip to content

path/filepath: Match does not use Glob patterns #41394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vatine opened this issue Sep 15, 2020 · 4 comments
Closed

path/filepath: Match does not use Glob patterns #41394

vatine opened this issue Sep 15, 2020 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@vatine
Copy link

vatine commented Sep 15, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14 linux/amd64

Does this issue reproduce with the latest release?

Based on docuemntation and the Go playground, yes. https://play.golang.org/p/WHq5MYYn_yf

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ingvar/.cache/go-build"
GOENV="/home/ingvar/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ingvar/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ingvar/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build667987227=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I passed the pattern "ga*[!k]" to filepath.Match expecting it to not match the string "gazonk" (as it clearly states it must match the entire pattern, and the glob-like syntax for a negated character class is [!...]). It turns out that filepath.Match actually uses regexp-like syntx for character classes.

https://play.golang.org/p/WHq5MYYn_yf

What did you expect to see?

I expected a function that says "shell file name pattern" to understand glob patterns. Especially since filepath.Glob says "uses the same pattern as Match".

What did you see instead?

I saw a function that partially uses glob patterns and partially (well, specifically for character classes) uses regexp patterns.

@toothrot toothrot changed the title path/filepath does not use glob patterns path/filepath: Match does not use glob patterns Sep 15, 2020
@toothrot toothrot changed the title path/filepath: Match does not use glob patterns path/filepath: Match does not use Glob patterns Sep 15, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 15, 2020
@toothrot toothrot added this to the Backlog milestone Sep 15, 2020
@toothrot
Copy link
Contributor

I believe the negation is documented as ^: https://play.golang.org/p/9zwuCeWNtXS

filepath.Glob does call Match: https://github.com/golang/go/blob/go1.15.2/src/path/filepath/match.go#L328

I'm not sure if these patterns are changeable without breaking any existing Go programs. See also the long discussion at #11862.

/cc @robpike @rsc

@ianlancetaylor
Copy link
Member

filepath.Match documents the exact syntax that it supports: https://golang.org/pkg/path/filepath/#Match .

I agree that in the POSIX shell definition, ! negates a character class and ^ does not. I guess we got that wrong. (In the bash shell, both ! and ^ negate a character class).

Unfortunately, we can't change it now. Sorry.

@vatine
Copy link
Author

vatine commented Sep 16, 2020

Would it be worth keeping "allow both ! and ^ for character class negation" in mind for Go2?

@ianlancetaylor
Copy link
Member

Well, path/filepath/v2, but, sure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants