Skip to content

Commit 78b5356

Browse files
authored
fileserver: do not double-escape paths (#4447)
1 parent 6f9b6ad commit 78b5356

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

modules/caddyhttp/caddyhttp.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"io"
2121
"net"
2222
"net/http"
23-
"net/url"
2423
"path/filepath"
2524
"strconv"
2625
"strings"
@@ -228,7 +227,6 @@ func StatusCodeMatches(actual, configured int) bool {
228227
// never be outside of root. The resulting path can be used
229228
// with the local file system.
230229
func SanitizedPathJoin(root, reqPath string) string {
231-
reqPath, _ = url.PathUnescape(reqPath)
232230
if root == "" {
233231
root = "."
234232
}

modules/caddyhttp/fileserver/browsetplcontext.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root
4343

4444
isDir := f.IsDir() || isSymlinkTargetDir(f, root, urlPath)
4545

46-
u := url.URL{Path: url.PathEscape(name)}
47-
4846
// add the slash after the escape of path to avoid escaping the slash as well
4947
if isDir {
50-
u.Path += "/"
48+
name += "/"
5149
dirCount++
5250
} else {
5351
fileCount++
@@ -67,6 +65,8 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root
6765
// was already set above.
6866
}
6967

68+
u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
69+
7070
fileInfos = append(fileInfos, fileInfo{
7171
IsDir: isDir,
7272
IsSymlink: fileIsSymlink,

0 commit comments

Comments
 (0)