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
This commit is contained in:
Francis Lavoie
2020-09-16 20:09:28 -04:00
committed by GitHub
parent b01bb275b3
commit b95b87381a
6 changed files with 165 additions and 35 deletions

View File

@ -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