mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package strutils_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "github.com/yusing/go-proxy/internal/utils/strutils"
|
|
expect "github.com/yusing/go-proxy/internal/utils/testing"
|
|
)
|
|
|
|
func TestSanitizeURI(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "empty string",
|
|
input: "",
|
|
expected: "/",
|
|
},
|
|
{
|
|
name: "single slash",
|
|
input: "/",
|
|
expected: "/",
|
|
},
|
|
{
|
|
name: "normal path",
|
|
input: "/path/to/resource",
|
|
expected: "/path/to/resource",
|
|
},
|
|
{
|
|
name: "path without leading slash",
|
|
input: "path/to/resource",
|
|
expected: "/path/to/resource",
|
|
},
|
|
{
|
|
name: "path with dot segments",
|
|
input: "/path/./to/../resource",
|
|
expected: "/path/resource",
|
|
},
|
|
{
|
|
name: "double slash prefix",
|
|
input: "//path/to/resource",
|
|
expected: "/",
|
|
},
|
|
{
|
|
name: "backslash prefix",
|
|
input: "/\\path/to/resource",
|
|
expected: "/",
|
|
},
|
|
{
|
|
name: "path with multiple slashes",
|
|
input: "/path//to///resource",
|
|
expected: "/path/to/resource",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := SanitizeURI(tt.input)
|
|
expect.Equal(t, result, tt.expected)
|
|
})
|
|
}
|
|
}
|