package swampfile import ( "github.com/matryer/is" "testing" ) func TestSwampPathNotStrict(t *testing.T) { cases := []struct { dirty string clean string }{ {"/", "/"}, {"..", "/"}, {"/../a", "/a"}, {"/../a/../a", "/a"}, {"../b", "/b"}, } is := is.New(t) for _, tc := range cases { rf := FileReference{ tc.dirty, "ns", } rc, err := rf.Clean(false) is.NoErr(err) is.Equal(rc.Path, tc.clean) } } func TestSwampPathStrict(t *testing.T) { is := is.New(t) rf := FileReference{ "/a/../b", "ns", } _, err := rf.Clean(true) is.Equal(err, ErrUnacceptablePath) }