mirror of https://github.com/caddyserver/caddy.git
fileserver: do not double-escape paths (#4447)
This commit is contained in:
parent
6f9b6ad78e
commit
78b5356f2b
|
@ -20,7 +20,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -228,7 +227,6 @@ func StatusCodeMatches(actual, configured int) bool {
|
||||||
// never be outside of root. The resulting path can be used
|
// never be outside of root. The resulting path can be used
|
||||||
// with the local file system.
|
// with the local file system.
|
||||||
func SanitizedPathJoin(root, reqPath string) string {
|
func SanitizedPathJoin(root, reqPath string) string {
|
||||||
reqPath, _ = url.PathUnescape(reqPath)
|
|
||||||
if root == "" {
|
if root == "" {
|
||||||
root = "."
|
root = "."
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,9 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root
|
||||||
|
|
||||||
isDir := f.IsDir() || isSymlinkTargetDir(f, root, urlPath)
|
isDir := f.IsDir() || isSymlinkTargetDir(f, root, urlPath)
|
||||||
|
|
||||||
u := url.URL{Path: url.PathEscape(name)}
|
|
||||||
|
|
||||||
// add the slash after the escape of path to avoid escaping the slash as well
|
// add the slash after the escape of path to avoid escaping the slash as well
|
||||||
if isDir {
|
if isDir {
|
||||||
u.Path += "/"
|
name += "/"
|
||||||
dirCount++
|
dirCount++
|
||||||
} else {
|
} else {
|
||||||
fileCount++
|
fileCount++
|
||||||
|
@ -67,6 +65,8 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root
|
||||||
// was already set above.
|
// was already set above.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
|
||||||
|
|
||||||
fileInfos = append(fileInfos, fileInfo{
|
fileInfos = append(fileInfos, fileInfo{
|
||||||
IsDir: isDir,
|
IsDir: isDir,
|
||||||
IsSymlink: fileIsSymlink,
|
IsSymlink: fileIsSymlink,
|
||||||
|
|
Loading…
Reference in New Issue