]> Cypherpunks repositories - gostls13.git/commitdiff
io/fs: backslash is always a glob meta character
authorIan Lance Taylor <iant@golang.org>
Tue, 9 Feb 2021 00:32:39 +0000 (16:32 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 9 Feb 2021 01:22:45 +0000 (01:22 +0000)
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>
src/io/fs/glob.go
src/io/fs/glob_test.go

index 549f217542967500bf6f8a96599a234da49bb13a..45d9cb61b9632af83bf9834ef99d47e6133b193b 100644 (file)
@@ -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
                }
        }
index f0d791fab5aba9bb6134cfca789a609b8263cc6c..f19bebed77f6c7c7e9fad7017b94b9c557a77bca 100644 (file)
@@ -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)