Skip to content
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

path/filepath: Glob fails if it has a wildcard and ends with / #33617

Open
BlackHole1 opened this issue Aug 13, 2019 · 1 comment

Comments

@BlackHole1
Copy link

commented Aug 13, 2019

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

$ go version
go version go1.12 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/black-hole/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/black-hole/.gvm/pkgsets/go1.12/global"
GOPROXY=""
GORACE=""
GOROOT="/Users/black-hole/.gvm/gos/go1.12"
GOTMPDIR=""
GOTOOLDIR="/Users/black-hole/.gvm/gos/go1.12/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/82/jkr30dwj24ncf6ng3tdv9kd40000gn/T/go-build925523187=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

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

What did you expect to see?

Accurate return path

What did you see instead?

Cannot match when there is a wildcard in the path and the last character is /

Other

image

@BlackHole1 BlackHole1 changed the title path/filePath: If the function Glob has a wildcard and the last string is /, it does not capture correctly. path/filePath: If the function Glob has a wildcard and the last string is /, it does not capture correctly Aug 13, 2019

@agnivade agnivade added this to the Unplanned milestone Aug 13, 2019

@jamdagni86

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2019

The function first uses filepath.Split to get the parent directory of the given path. When a trailing slash is present, filepath.Split returns the path as it is as it can't split it further. The fix is to clean the path before calling filepath.Split

dir, file := Split(pattern)
volumeLen := 0
if runtime.GOOS == "windows" {
volumeLen, dir = cleanGlobPathWindows(dir)
} else {
dir = cleanGlobPath(dir)
}

@ianlancetaylor ianlancetaylor changed the title path/filePath: If the function Glob has a wildcard and the last string is /, it does not capture correctly path/filepath: Glob fails if it has a wildcard and ends with / Aug 16, 2019

@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Go1.14 Aug 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.