summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/caddyhttp_test.go
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2022-08-16 08:48:57 -0600
committerGitHub <noreply@github.com>2022-08-16 08:48:57 -0600
commita479943acd70068c4b80d3a8f4b8dd7ab93ca2ba (patch)
treef50a45b3b0c8c8475b783583967c1175f5e6673c /modules/caddyhttp/caddyhttp_test.go
parentdc62d468e9645f52a5e1b4f6093dff65137ab3fe (diff)
caddyhttp: Smarter path matching and rewriting (#4948)
Co-authored-by: RussellLuo <luopeng.he@gmail.com>
Diffstat (limited to 'modules/caddyhttp/caddyhttp_test.go')
-rw-r--r--modules/caddyhttp/caddyhttp_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/caddyhttp/caddyhttp_test.go b/modules/caddyhttp/caddyhttp_test.go
index 09011fe..1bca4d6 100644
--- a/modules/caddyhttp/caddyhttp_test.go
+++ b/modules/caddyhttp/caddyhttp_test.go
@@ -92,3 +92,60 @@ func TestSanitizedPathJoin(t *testing.T) {
}
}
}
+
+func TestCleanPath(t *testing.T) {
+ for i, tc := range []struct {
+ input string
+ mergeSlashes bool
+ expect string
+ }{
+ {
+ input: "/foo",
+ expect: "/foo",
+ },
+ {
+ input: "/foo/",
+ expect: "/foo/",
+ },
+ {
+ input: "//foo",
+ expect: "//foo",
+ },
+ {
+ input: "//foo",
+ mergeSlashes: true,
+ expect: "/foo",
+ },
+ {
+ input: "/foo//bar/",
+ mergeSlashes: true,
+ expect: "/foo/bar/",
+ },
+ {
+ input: "/foo/./.././bar",
+ expect: "/bar",
+ },
+ {
+ input: "/foo//./..//./bar",
+ expect: "/foo//bar",
+ },
+ {
+ input: "/foo///./..//./bar",
+ expect: "/foo///bar",
+ },
+ {
+ input: "/foo///./..//.",
+ expect: "/foo//",
+ },
+ {
+ input: "/foo//./bar",
+ expect: "/foo//bar",
+ },
+ } {
+ actual := CleanPath(tc.input, tc.mergeSlashes)
+ if actual != tc.expect {
+ t.Errorf("Test %d [input='%s' mergeSlashes=%t]: Got '%s', expected '%s'",
+ i, tc.input, tc.mergeSlashes, actual, tc.expect)
+ }
+ }
+}