aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-02-08 16:32:39 -0800
committerIan Lance Taylor <iant@golang.org>2021-02-09 01:22:45 +0000
commitcea4e21b525ad6b465f62741680eaa0a44e9cc3e (patch)
tree60912708d4128a431932acc0d9fcbf21177238bb
parentdc725bfb3c3f29c7395e088d25ef6bf8dba8f129 (diff)
downloadgo-cea4e21b525ad6b465f62741680eaa0a44e9cc3e.tar.gz
go-cea4e21b525ad6b465f62741680eaa0a44e9cc3e.zip
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>
-rw-r--r--src/io/fs/glob.go5
-rw-r--r--src/io/fs/glob_test.go3
2 files changed, 4 insertions, 4 deletions
diff --git a/src/io/fs/glob.go b/src/io/fs/glob.go
index 549f2175429..45d9cb61b96 100644
--- a/src/io/fs/glob.go
+++ b/src/io/fs/glob.go
@@ -6,7 +6,6 @@ package fs
import (
"path"
- "runtime"
)
// 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.
func hasMeta(path string) bool {
for i := 0; i < len(path); i++ {
- c := path[i]
- if c == '*' || c == '?' || c == '[' || runtime.GOOS == "windows" && c == '\\' {
+ switch path[i] {
+ case '*', '?', '[', '\\':
return true
}
}
diff --git a/src/io/fs/glob_test.go b/src/io/fs/glob_test.go
index f0d791fab5a..f19bebed77f 100644
--- a/src/io/fs/glob_test.go
+++ b/src/io/fs/glob_test.go
@@ -17,6 +17,7 @@ var globTests = []struct {
}{
{os.DirFS("."), "glob.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", "fs/glob.go"},
}
@@ -32,7 +33,7 @@ func TestGlob(t *testing.T) {
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)
if err != nil {
t.Errorf("Glob error for %q: %s", pattern, err)