@@ -25,26 +25,58 @@ func TestWithFSTest(t *testing.T) {
2525 iofs := New (memfs )
2626
2727 files := map [string ]string {
28- "foo.txt" : "hello, world" ,
29- "bar.txt" : "goodbye, world" ,
30- filepath . Join ( "dir" , " baz.txt") : "こんにちわ, world" ,
28+ "foo.txt" : "hello, world" ,
29+ "bar.txt" : "goodbye, world" ,
30+ "dir/ baz.txt" : "こんにちわ, world" ,
3131 }
3232 createdFiles := make ([]string , 0 , len (files ))
3333 for filename , contents := range files {
3434 makeFile (t , memfs , filename , contents )
3535 createdFiles = append (createdFiles , filename )
3636 }
3737
38- if runtime .GOOS == "windows" {
39- t .Skip ("fstest.TestFS is not yet windows path aware" )
40- }
41-
4238 err := fstest .TestFS (iofs , createdFiles ... )
4339 if err != nil {
4440 checkFsTestError (t , err , files )
4541 }
4642}
4743
44+ // TestOpenForwardSlashPath verifies that Open works with forward-slash paths
45+ // on all platforms. This is a regression test ensuring filepath.Clean is not
46+ // used when cleaning paths in Open() (it should use path.Clean) so valid
47+ // fs.FS paths like "dir/file.txt" are not rejected on Windows.
48+ func TestOpenForwardSlashPath (t * testing.T ) {
49+ t .Parallel ()
50+ mem := memfs .New ()
51+ adapter := New (mem )
52+
53+ makeFile (t , mem , "dir/subdir/file.txt" , "content" )
54+
55+ tests := []struct {
56+ name string
57+ path string
58+ wantErr bool
59+ }{
60+ {"simple-nested" , "dir/subdir/file.txt" , false },
61+ {"directory" , "dir/subdir" , false },
62+ {"dot-path" , "." , false },
63+ {"absolute-path-rejected" , "/dir/subdir/file.txt" , true },
64+ }
65+
66+ for _ , tt := range tests {
67+ t .Run (tt .name , func (t * testing.T ) {
68+ t .Parallel ()
69+ f , err := adapter .Open (tt .path )
70+ if tt .wantErr {
71+ require .Error (t , err )
72+ return
73+ }
74+ require .NoError (t , err )
75+ require .NoError (t , f .Close ())
76+ })
77+ }
78+ }
79+
4880func TestDeletes (t * testing.T ) {
4981 t .Parallel ()
5082 memfs := memfs .New ()
0 commit comments