diff options
author | Francis Lavoie <[email protected]> | 2022-04-08 15:06:17 -0400 |
---|---|---|
committer | Francis Lavoie <[email protected]> | 2022-04-08 15:06:17 -0400 |
commit | 458c64af665904dbd51f7ad000ab4221d8fb2cea (patch) | |
tree | 347fc213c2aa698f617f3557fb3d908f8808cc38 | |
parent | e7795501ff0052a498ed0c8efd522e5cdfd3c69d (diff) | |
download | caddy-458c64af665904dbd51f7ad000ab4221d8fb2cea.tar.gz caddy-458c64af665904dbd51f7ad000ab4221d8fb2cea.zip |
Ensure root is always shownfileserver-show
-rw-r--r-- | modules/caddyhttp/fileserver/staticfiles.go | 7 | ||||
-rw-r--r-- | modules/caddyhttp/fileserver/staticfiles_test.go | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go index bb9fc4357..0777ca1d0 100644 --- a/modules/caddyhttp/fileserver/staticfiles.go +++ b/modules/caddyhttp/fileserver/staticfiles.go @@ -519,6 +519,13 @@ func fileHidden(filename string, show []string, hide []string) bool { // cache the components of the input filename var components []string + // if the filename is the root of the fileserver, then + // it should always be shown, because otherwise the + // index would always be hidden + if filename == separator { + goto shown + } + for _, s := range show { if !strings.Contains(s, separator) { // if there is no separator in s, then we assume the user diff --git a/modules/caddyhttp/fileserver/staticfiles_test.go b/modules/caddyhttp/fileserver/staticfiles_test.go index bd0370518..1f9232206 100644 --- a/modules/caddyhttp/fileserver/staticfiles_test.go +++ b/modules/caddyhttp/fileserver/staticfiles_test.go @@ -155,6 +155,12 @@ func TestFileHidden(t *testing.T) { expect: true, }, { + inputShow: []string{"/foo"}, + inputHide: nil, + inputPath: "/", + expect: false, + }, + { inputShow: []string{"*.txt"}, inputHide: []string{"/foo"}, inputPath: "/foo/bar.txt", |