mirror of
https://github.com/golang/go.git
synced 2025-10-28 07:14:14 +00:00
io/fs: backslash is always a glob meta character
Fixes #44171 Change-Id: I2d3437a2f5b9fa0358e4664e1a8eacebed975eed Reviewed-on: https://go-review.googlesource.com/c/go/+/290512 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
dc725bfb3c
commit
cea4e21b52
2 changed files with 4 additions and 4 deletions
|
|
@ -6,7 +6,6 @@ package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A GlobFS is a file system with a Glob method.
|
// A GlobFS is a file system with a Glob method.
|
||||||
|
|
@ -111,8 +110,8 @@ func glob(fs FS, dir, pattern string, matches []string) (m []string, e error) {
|
||||||
// recognized by path.Match.
|
// recognized by path.Match.
|
||||||
func hasMeta(path string) bool {
|
func hasMeta(path string) bool {
|
||||||
for i := 0; i < len(path); i++ {
|
for i := 0; i < len(path); i++ {
|
||||||
c := path[i]
|
switch path[i] {
|
||||||
if c == '*' || c == '?' || c == '[' || runtime.GOOS == "windows" && c == '\\' {
|
case '*', '?', '[', '\\':
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ var globTests = []struct {
|
||||||
}{
|
}{
|
||||||
{os.DirFS("."), "glob.go", "glob.go"},
|
{os.DirFS("."), "glob.go", "glob.go"},
|
||||||
{os.DirFS("."), "gl?b.go", "glob.go"},
|
{os.DirFS("."), "gl?b.go", "glob.go"},
|
||||||
|
{os.DirFS("."), `gl\ob.go`, "glob.go"},
|
||||||
{os.DirFS("."), "*", "glob.go"},
|
{os.DirFS("."), "*", "glob.go"},
|
||||||
{os.DirFS(".."), "*/glob.go", "fs/glob.go"},
|
{os.DirFS(".."), "*/glob.go", "fs/glob.go"},
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +33,7 @@ func TestGlob(t *testing.T) {
|
||||||
t.Errorf("Glob(%#q) = %#v want %v", tt.pattern, matches, tt.result)
|
t.Errorf("Glob(%#q) = %#v want %v", tt.pattern, matches, tt.result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, pattern := range []string{"no_match", "../*/no_match"} {
|
for _, pattern := range []string{"no_match", "../*/no_match", `\*`} {
|
||||||
matches, err := Glob(os.DirFS("."), pattern)
|
matches, err := Glob(os.DirFS("."), pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Glob error for %q: %s", pattern, err)
|
t.Errorf("Glob error for %q: %s", pattern, err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue