From 33c70f418f780f8e9524c73fbf4bbdbdbb9d7500 Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Thu, 16 Sep 2021 23:40:31 +0300 Subject: 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 --- modules/caddyhttp/fileserver/browsetplcontext.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/caddyhttp/fileserver/browsetplcontext.go') 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), -- cgit v1.2.3