提交 ec7623bb 作者: Adrian Ulrich 提交者: Stephen Whitmore

Use net/url to escape paths in web-ui

License: MIT
Signed-off-by: 's avatarAdrian Ulrich <adrian@blinkenlights.ch>
上级 9a923b4a
......@@ -2,6 +2,7 @@ package corehttp
import (
"html/template"
"net/url"
"path"
"strings"
......@@ -45,6 +46,12 @@ func init() {
return "ipfs-" + ext[1:] // slice of the first dot
}
// custom template-escaping function to escape a full path, including '#' and '?'
urlEscape := func(rawUrl string) string {
pathUrl := url.URL{Path: rawUrl}
return pathUrl.String()
}
// Directory listing template
dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html")
if err != nil {
......@@ -53,5 +60,6 @@ func init() {
listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{
"iconFromExt": iconFromExt,
"urlEscape": urlEscape,
}).Parse(string(dirIndexBytes)))
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论