summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/fileserver/browsetplcontext.go
diff options
context:
space:
mode:
authorMohammed Al Sahaf <msaa1990@gmail.com>2021-11-23 11:13:09 +0300
committerGitHub <noreply@github.com>2021-11-23 03:13:09 -0500
commit1e10f6f725189a371a923a329084f1c3f608ae38 (patch)
treeb7bd3e17c4b365a9cde81c160b3b664b94440ddf /modules/caddyhttp/fileserver/browsetplcontext.go
parentc8b5a81607c9c2799f46f42154ee311884723aa4 (diff)
fileserver: browse: do not encode the paths in breadcrumbs and page title (#4410)
Diffstat (limited to 'modules/caddyhttp/fileserver/browsetplcontext.go')
-rw-r--r--modules/caddyhttp/fileserver/browsetplcontext.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/modules/caddyhttp/fileserver/browsetplcontext.go b/modules/caddyhttp/fileserver/browsetplcontext.go
index 2c57e52..b1b8e9e 100644
--- a/modules/caddyhttp/fileserver/browsetplcontext.go
+++ b/modules/caddyhttp/fileserver/browsetplcontext.go
@@ -77,9 +77,9 @@ func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, root
Mode: f.Mode(),
})
}
-
+ name, _ := url.PathUnescape(urlPath)
return browseTemplateContext{
- Name: path.Base(urlPath),
+ Name: path.Base(name),
Path: urlPath,
CanGoUp: canGoUp,
Items: fileInfos,
@@ -133,13 +133,16 @@ func (l browseTemplateContext) Breadcrumbs() []crumb {
if lpath[len(lpath)-1] == '/' {
lpath = lpath[:len(lpath)-1]
}
-
parts := strings.Split(lpath, "/")
result := make([]crumb, len(parts))
for i, p := range parts {
if i == 0 && p == "" {
p = "/"
}
+ // the directory name could include an encoded slash in its path,
+ // so the item name should be unescaped in the loop rather than unescaping the
+ // entire path outside the loop.
+ p, _ = url.PathUnescape(p)
lnk := strings.Repeat("../", len(parts)-i-1)
result[i] = crumb{Link: lnk, Text: p}
}