2016-12-10 12:59:54 +01:00
|
|
|
package ctlsock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSanitizePath(t *testing.T) {
|
|
|
|
testCases := [][]string{
|
|
|
|
{"", ""},
|
|
|
|
{".", ""},
|
|
|
|
{"/", ""},
|
|
|
|
{"foo", "foo"},
|
|
|
|
{"/foo", "foo"},
|
|
|
|
{"foo/", "foo"},
|
|
|
|
{"/foo/", "foo"},
|
|
|
|
{"/foo/./foo", "foo/foo"},
|
|
|
|
{"./", ""},
|
2017-01-29 15:24:47 +01:00
|
|
|
{"..", ""},
|
|
|
|
{"foo/../..", ""},
|
|
|
|
{"foo/../../aaaaaa", ""},
|
|
|
|
{"/foo/../../aaaaaa", ""},
|
2017-02-05 18:05:35 +01:00
|
|
|
{"/////", ""},
|
2016-12-10 12:59:54 +01:00
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
res := SanitizePath(tc[0])
|
|
|
|
if res != tc[1] {
|
|
|
|
t.Errorf("%q: got %q, want %q", tc[0], res, tc[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|