Skip to content

Commit

Permalink
fileserver: do not double-escape paths (#4447)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammed90 authored Dec 11, 2021
1 parent 6f9b6ad commit 78b5356
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 0 additions & 2 deletions modules/caddyhttp/caddyhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"io"
"net"
"net/http"
"net/url"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -228,7 +227,6 @@ func StatusCodeMatches(actual, configured int) bool {
// never be outside of root. The resulting path can be used
// with the local file system.
func SanitizedPathJoin(root, reqPath string) string {
reqPath, _ = url.PathUnescape(reqPath)
if root == "" {
root = "."
}
Expand Down
6 changes: 3 additions & 3 deletions modules/caddyhttp/fileserver/browsetplcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root

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
if isDir {
u.Path += "/"
name += "/"
dirCount++
} else {
fileCount++
Expand All @@ -67,6 +65,8 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root
// was already set above.
}

u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name

fileInfos = append(fileInfos, fileInfo{
IsDir: isDir,
IsSymlink: fileIsSymlink,
Expand Down

0 comments on commit 78b5356

Please sign in to comment.