Open BlackHole1 opened 5 years ago
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
Hello @BlackHole1, thank you for the report! @jamdagni86 would you like to send a CL as you had recommended above, and a test following up too, for Go1.14?
Change https://golang.org/cl/207837 mentions this issue: path/filepath: Glob fails if it has a wildcard and ends with /
I don't understand this issue report. The docs for filepath.Glob
say that it uses the rules for filepath.Match
. The docs for filepath.Match
do not say that a pattern with a trailing slash matches the same name without the trailing slash.
What is the actual bug here? Where do the functions not act as documented?
With or without the slash in the trailing, I think the matching result should be the same, but it is not the case.
The documentation for Glob
says that it follows the same as rules as Match
. The documentation for Match
does not say anything about a trailing slash. Consider https://play.golang.org/p/6j4icmyaYpp.
What do you think Glob("/usr/*/go/")
should print?
I think their output should be the same. The last slash should not affect the match.
The Match
design principle is to follow http://man7.org/linux/man-pages/man7/glob.7.html
Although I didn't find the relevant instructions in the above document, I tried several shells, and the results of their matching have nothing to do with the last slash.
I have a file /home/iant/hello.go
. Using bash:
> echo /home/*/hello.go
/home/iant/hello.go
> echo /home/*/hello.go/
/home/*/hello.go/
So I don't agree with you that the last slash does not affect the match. It does affect it.
It seems that if it is a file at the end, it is influential. But when the last is the directory, there is no affect.
> tree ./test
./test
├── a
│ └── x
│ └── 1.txt
└── b
└── x
└── 2.txt
4 directories, 2 files
> echo ./test/*/x/
./test/a/x/ ./test/b/x/
> echo ./test/*/x
./test/a/x ./test/b/x
> ls ./test/*/x/
./test/a/x/:
1.txt
./test/b/x/:
2.txt
> ls ./test/*/x
./test/a/x:
1.txt
./test/b/x:
2.txt
So it seems that we need to decide whether filepath.Glob
should permit a trailing slash to match a directory name.
I would like to confirm whether to modify filepath.Glob
or filepath.Match
?
I don't see how it is possible to change filepath.Match
for this, as filepath.Match
is only text based.
(That is of course an argument for not changing filepath.Glob
, which is currently defined in terms of filepath.Match
.)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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