Skip to content

Commit cea4e21

Browse files
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent dc725bf commit cea4e21

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/io/fs/glob.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package fs
66

77
import (
88
"path"
9-
"runtime"
109
)
1110

1211
// 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) {
111110
// recognized by path.Match.
112111
func hasMeta(path string) bool {
113112
for i := 0; i < len(path); i++ {
114-
c := path[i]
115-
if c == '*' || c == '?' || c == '[' || runtime.GOOS == "windows" && c == '\\' {
113+
switch path[i] {
114+
case '*', '?', '[', '\\':
116115
return true
117116
}
118117
}

src/io/fs/glob_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var globTests = []struct {
1717
}{
1818
{os.DirFS("."), "glob.go", "glob.go"},
1919
{os.DirFS("."), "gl?b.go", "glob.go"},
20+
{os.DirFS("."), `gl\ob.go`, "glob.go"},
2021
{os.DirFS("."), "*", "glob.go"},
2122
{os.DirFS(".."), "*/glob.go", "fs/glob.go"},
2223
}
@@ -32,7 +33,7 @@ func TestGlob(t *testing.T) {
3233
t.Errorf("Glob(%#q) = %#v want %v", tt.pattern, matches, tt.result)
3334
}
3435
}
35-
for _, pattern := range []string{"no_match", "../*/no_match"} {
36+
for _, pattern := range []string{"no_match", "../*/no_match", `\*`} {
3637
matches, err := Glob(os.DirFS("."), pattern)
3738
if err != nil {
3839
t.Errorf("Glob error for %q: %s", pattern, err)

0 commit comments

Comments
 (0)