532ef15417
Paths that start with ".." were previously accepted as-is.
30 lines
500 B
Go
30 lines
500 B
Go
package ctlsock
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizePath(t *testing.T) {
|
|
testCases := [][]string{
|
|
{"", ""},
|
|
{".", ""},
|
|
{"/", ""},
|
|
{"foo", "foo"},
|
|
{"/foo", "foo"},
|
|
{"foo/", "foo"},
|
|
{"/foo/", "foo"},
|
|
{"/foo/./foo", "foo/foo"},
|
|
{"./", ""},
|
|
{"..", ""},
|
|
{"foo/../..", ""},
|
|
{"foo/../../aaaaaa", ""},
|
|
{"/foo/../../aaaaaa", ""},
|
|
}
|
|
for _, tc := range testCases {
|
|
res := SanitizePath(tc[0])
|
|
if res != tc[1] {
|
|
t.Errorf("%q: got %q, want %q", tc[0], res, tc[1])
|
|
}
|
|
}
|
|
}
|