Skip to content

Commit

Permalink
testing/fstest: treat dash specially when building glob
Browse files Browse the repository at this point in the history
"[-]" is not a valid path.Match pattern.

Fixes #44474

Change-Id: I0932bbf08ffb8ad0c5337d69d0893f53c1ba89ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/294869
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
  • Loading branch information
ianlancetaylor committed Feb 25, 2021
1 parent 37ca84a commit ad17b65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/testing/fstest/testfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (t *fsTester) checkGlob(dir string, list []fs.DirEntry) {
for i, e := range elem {
var pattern []rune
for j, r := range e {
if r == '*' || r == '?' || r == '\\' || r == '[' {
if r == '*' || r == '?' || r == '\\' || r == '[' || r == '-' {
pattern = append(pattern, '\\', r)
continue
}
Expand Down
9 changes: 9 additions & 0 deletions src/testing/fstest/testfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ func TestSymlink(t *testing.T) {
t.Fatal(err)
}
}

func TestDash(t *testing.T) {
m := MapFS{
"a-b/a": {Data: []byte("a-b/a")},
}
if err := TestFS(m, "a-b/a"); err != nil {
t.Error(err)
}
}

0 comments on commit ad17b65

Please sign in to comment.