From 5deea4c2425fd8aa6dee642c63a1bc43e090d04b Mon Sep 17 00:00:00 2001 From: George Adams Date: Tue, 19 Nov 2024 10:05:27 +0000 Subject: Revert "os: check for valid Windows path when creating files" This reverts commit CL 618496. Reason for revert: https://github.com/golang/go/issues/54040#issuecomment-2485151973 Change-Id: I3bf27f7fdd475a005cb6aa190994153504e96fb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/629595 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Quim Muntal LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil --- src/os/os_windows_test.go | 73 ----------------------------------------------- 1 file changed, 73 deletions(-) (limited to 'src/os/os_windows_test.go') diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index 9208fe3b16..31c379011c 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -1563,76 +1563,3 @@ func TestReadDirNoFileID(t *testing.T) { t.Errorf("SameFile(%v, %v) = false; want true", f2, f2s) } } - -func TestOpen_InvalidPath(t *testing.T) { - dir := t.TempDir() - - file, err := os.Open(dir + ".") - if err != nil { - t.Errorf("Open(%q) should have succeeded, got %v", dir+".", err) - } else { - file.Close() - } - - file, err = os.Open(dir + " ") - if err != nil { - t.Errorf("Open(%q) should have succeeded, got %v", dir+" ", err) - } else { - file.Close() - } -} - -func TestMkdirAll_InvalidPath(t *testing.T) { - // Parent folder contains traling spaces - path := `C:\temp\folder \this one fails` - err := os.MkdirAll(path, 0644) - if err == nil { - t.Errorf("MkdirAll(%q) should have failed", path) - } else if !strings.Contains(err.Error(), "invalid path: cannot end with a space or period") { - t.Errorf("expected errInvalidPath for path %q, got %v", path, err) - } -} - -func TestCreate_InvalidPath(t *testing.T) { - testInvalidPath(t, func(_, path string) error { - _, err := os.Create(path) - return err - }) -} - -func TestMkdir_InvalidPath(t *testing.T) { - testInvalidPath(t, func(_, path string) error { - return os.Mkdir(path, 0644) - }) -} - -func TestRename_InvalidPath(t *testing.T) { - testInvalidPath(t, os.Rename) -} - -func TestLink_InvalidPath(t *testing.T) { - testInvalidPath(t, os.Link) -} - -func TestSymlink_InvalidPath(t *testing.T) { - testInvalidPath(t, os.Symlink) -} - -func testInvalidPath(t *testing.T, fn func(src, dest string) error) { - dir := t.TempDir() - - // Test invalid paths (with trailing space and period) - invalidPaths := []string{ - filepath.Join(dir, "invalid_dir "), // path ending in space - filepath.Join(dir, "invalid_dir."), // path ending in period - } - - for _, path := range invalidPaths { - err := fn(dir, path) - if err == nil { - t.Errorf("(%q, %q) should have failed", dir, path) - } else if !strings.Contains(err.Error(), "invalid path: cannot end with a space or period") { - t.Errorf("expected errInvalidPath for path %q, got %v", path, err) - } - } -} -- cgit v1.3