mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-24 08:26:58 -04:00
httpserver: Base path of "/" matches all paths, even empty ones
Fixes #1645
This commit is contained in:
61
caddyhttp/httpserver/path_test.go
Normal file
61
caddyhttp/httpserver/path_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package httpserver
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPathMatches(t *testing.T) {
|
||||
for i, testcase := range []struct {
|
||||
reqPath Path
|
||||
rulePath string
|
||||
shouldMatch bool
|
||||
caseInsensitive bool
|
||||
}{
|
||||
{
|
||||
reqPath: "/",
|
||||
rulePath: "/",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
reqPath: "/foo/bar",
|
||||
rulePath: "/foo",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
reqPath: "/foobar",
|
||||
rulePath: "/foo/",
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
reqPath: "/foobar",
|
||||
rulePath: "/foo/bar",
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
reqPath: "/Foobar",
|
||||
rulePath: "/Foo",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
|
||||
reqPath: "/FooBar",
|
||||
rulePath: "/Foo",
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
reqPath: "/foobar",
|
||||
rulePath: "/FooBar",
|
||||
shouldMatch: true,
|
||||
caseInsensitive: true,
|
||||
},
|
||||
{
|
||||
reqPath: "",
|
||||
rulePath: "/", // a lone forward slash means to match all requests (see issue #1645)
|
||||
shouldMatch: true,
|
||||
},
|
||||
} {
|
||||
CaseSensitivePath = !testcase.caseInsensitive
|
||||
if got, want := testcase.reqPath.Matches(testcase.rulePath), testcase.shouldMatch; got != want {
|
||||
t.Errorf("Test %d: For request path '%s' and other path '%s': expected %v, got %v",
|
||||
i, testcase.reqPath, testcase.rulePath, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user