From 97cee43c93cfccded197cd281f0a5885cdb605b4 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Jun 2021 15:33:54 +0200 Subject: testing: drop unusual characters from TempDir directory name Only use safe characters of the test name for the os.MkdirTemp pattern. This currently includes the alphanumeric characters and ASCII punctuation characters known not to interact with globs. Fixes #46624 Change-Id: I402c34775b943fed9b97963c52f79245cc16dc1d Reviewed-on: https://go-review.googlesource.com/c/go/+/326010 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Go Bot Reviewed-by: Bryan C. Mills Reviewed-by: Ian Lance Taylor --- src/testing/testing_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/testing/testing_test.go') diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go index 55a4df4739..08ae23991f 100644 --- a/src/testing/testing_test.go +++ b/src/testing/testing_test.go @@ -58,6 +58,9 @@ func TestTempDir(t *testing.T) { t.Run("test:subtest", testTempDir) t.Run("test/..", testTempDir) t.Run("../test", testTempDir) + t.Run("test[]", testTempDir) + t.Run("test*", testTempDir) + t.Run("äöüéè", testTempDir) } func testTempDir(t *testing.T) { @@ -74,7 +77,7 @@ func testTempDir(t *testing.T) { if err != nil { t.Fatal(err) } - t.Errorf("directory %q stil exists: %v, isDir=%v", dir, fi, fi.IsDir()) + t.Errorf("directory %q still exists: %v, isDir=%v", dir, fi, fi.IsDir()) default: if !t.Failed() { t.Fatal("never received dir channel") @@ -108,6 +111,11 @@ func testTempDir(t *testing.T) { if len(files) > 0 { t.Errorf("unexpected %d files in TempDir: %v", len(files), files) } + + glob := filepath.Join(dir, "*.txt") + if _, err := filepath.Glob(glob); err != nil { + t.Error(err) + } } func TestSetenv(t *testing.T) { -- cgit v1.3