From ad17b65b340d5a40d0da1b4cbcdc239061e97c65 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 21 Feb 2021 15:28:41 -0800 Subject: [PATCH] testing/fstest: treat dash specially when building glob "[-]" 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Russ Cox --- src/testing/fstest/testfs.go | 2 +- src/testing/fstest/testfs_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go index 8fc8acaaf3bf1b..736bbf0590e981 100644 --- a/src/testing/fstest/testfs.go +++ b/src/testing/fstest/testfs.go @@ -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 } diff --git a/src/testing/fstest/testfs_test.go b/src/testing/fstest/testfs_test.go index 5b8813c3431339..aefb4b33617ab1 100644 --- a/src/testing/fstest/testfs_test.go +++ b/src/testing/fstest/testfs_test.go @@ -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) + } +}