diff options
author | Francis Lavoie <lavofr@gmail.com> | 2020-09-16 20:09:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-16 18:09:28 -0600 |
commit | b95b87381a282e1fe57295d145b71645d7801f07 (patch) | |
tree | 853f7368ac81f6ede2de30503201cf943841b34e /modules/caddyhttp/fileserver/staticfiles.go | |
parent | b01bb275b395643542ceca4fbc82bedea8e43937 (diff) |
fileserver: Fix try_files for directories; windows fix (#3684)
* fileserver: Fix try_files for directories, windows fix
* fileserver: Add new file type placeholder, refactoring, tests
* fileserver: Review cleanup
* fileserver: Flip the return args order
Diffstat (limited to 'modules/caddyhttp/fileserver/staticfiles.go')
-rw-r--r-- | modules/caddyhttp/fileserver/staticfiles.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go index 735352b..2a7e013 100644 --- a/modules/caddyhttp/fileserver/staticfiles.go +++ b/modules/caddyhttp/fileserver/staticfiles.go @@ -23,7 +23,6 @@ import ( "mime" "net/http" "os" - "path" "path/filepath" "strconv" "strings" @@ -323,7 +322,18 @@ func sanitizedPathJoin(root, reqPath string) string { if root == "" { root = "." } - return filepath.Join(root, filepath.FromSlash(path.Clean("/"+reqPath))) + + path := filepath.Join(root, filepath.Clean("/"+reqPath)) + + // filepath.Join also cleans the path, and cleaning strips + // the trailing slash, so we need to re-add it afterwards. + // if the length is 1, then it's a path to the root, + // and that should return ".", so we don't append the separator. + if strings.HasSuffix(reqPath, "/") && len(reqPath) > 1 { + path += string(filepath.Separator) + } + + return path } // fileHidden returns true if filename is hidden |