diff options
author | Matt Holt <mholt@users.noreply.github.com> | 2020-11-02 14:20:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-02 14:20:12 -0700 |
commit | 8d038ca515ffaa4d37dca05a95181203b2db64e7 (patch) | |
tree | 09ec23687cebfe468f8079ad86facf4d40a7c31c /modules/caddyhttp/fileserver/caddyfile.go | |
parent | 937ec342010894f7a6239883b10f6a107ff82c9f (diff) |
fileserver: Improve and clarify file hiding logic (#3844)
* fileserver: Improve and clarify file hiding logic
* Oops, forgot to run integration tests
* Make this one integration test OS-agnostic
* See if this appeases the Windows gods
* D'oh
Diffstat (limited to 'modules/caddyhttp/fileserver/caddyfile.go')
-rw-r--r-- | modules/caddyhttp/fileserver/caddyfile.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/modules/caddyhttp/fileserver/caddyfile.go b/modules/caddyhttp/fileserver/caddyfile.go index 9b458b2..3acbfa9 100644 --- a/modules/caddyhttp/fileserver/caddyfile.go +++ b/modules/caddyhttp/fileserver/caddyfile.go @@ -15,6 +15,7 @@ package fileserver import ( + "path/filepath" "strings" "github.com/caddyserver/caddy/v2" @@ -85,7 +86,14 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) // hide the Caddyfile (and any imported Caddyfiles) if configFiles := h.Caddyfiles(); len(configFiles) > 0 { for _, file := range configFiles { + file = filepath.Clean(file) if !fileHidden(file, fsrv.Hide) { + // if there's no path separator, the file server module will hide all + // files by that name, rather than a specific one; but we want to hide + // only this specific file, so ensure there's always a path separator + if !strings.Contains(file, separator) { + file = "." + separator + file + } fsrv.Hide = append(fsrv.Hide, file) } } |