aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/testing/testing.go7
-rw-r--r--src/testing/testing_test.go1
2 files changed, 7 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 78681b605b..d50abea32f 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -1244,6 +1244,11 @@ func (c *common) TempDir() string {
if nonExistent {
c.Helper()
+ pattern := c.Name()
+ // Limit length of file names on disk.
+ // Invalid runes from slicing are dropped by strings.Map below.
+ pattern = pattern[:min(len(pattern), 64)]
+
// Drop unusual characters (such as path separators or
// characters interacting with globs) from the directory name to
// avoid surprising os.MkdirTemp behavior.
@@ -1263,7 +1268,7 @@ func (c *common) TempDir() string {
}
return -1
}
- pattern := strings.Map(mapper, c.Name())
+ pattern = strings.Map(mapper, pattern)
c.tempDir, c.tempDirErr = os.MkdirTemp("", pattern)
if c.tempDirErr == nil {
c.Cleanup(func() {
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go
index 907d0701f0..209291d322 100644
--- a/src/testing/testing_test.go
+++ b/src/testing/testing_test.go
@@ -89,6 +89,7 @@ func TestTempDir(t *testing.T) {
t.Run("test[]", testTempDir)
t.Run("test*", testTempDir)
t.Run("äöüéè", testTempDir)
+ t.Run(strings.Repeat("a", 300), testTempDir)
}
func testTempDir(t *testing.T) {