diff options
author | Mohammed Al Sahaf <msaa1990@gmail.com> | 2021-09-16 23:40:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 20:40:31 +0000 |
commit | 33c70f418f780f8e9524c73fbf4bbdbdbb9d7500 (patch) | |
tree | 7590c68508368624bf777e29850868f73cbbe35f /modules/caddyhttp/fileserver/browsetplcontext.go | |
parent | 2ebfda1ae93d356a2d3df53bf3411248886bafaf (diff) |
fileserver: properly handle escaped/non-ascii paths (#4332)
* fileserver: properly handle escaped/non-ascii paths
* fileserver: tests: accommodate Windows hate of colons in files names
Diffstat (limited to 'modules/caddyhttp/fileserver/browsetplcontext.go')
-rw-r--r-- | modules/caddyhttp/fileserver/browsetplcontext.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/modules/caddyhttp/fileserver/browsetplcontext.go b/modules/caddyhttp/fileserver/browsetplcontext.go index d420c48..6aa7501 100644 --- a/modules/caddyhttp/fileserver/browsetplcontext.go +++ b/modules/caddyhttp/fileserver/browsetplcontext.go @@ -42,15 +42,16 @@ 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 { - name += "/" + u.Path += "/" dirCount++ } else { fileCount++ } - u := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name - fileInfos = append(fileInfos, fileInfo{ IsDir: isDir, IsSymlink: isSymlink(f), |