提交 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 ...@@ -2,6 +2,7 @@ package corehttp
import ( import (
"html/template" "html/template"
"net/url"
"path" "path"
"strings" "strings"
...@@ -45,6 +46,12 @@ func init() { ...@@ -45,6 +46,12 @@ func init() {
return "ipfs-" + ext[1:] // slice of the first dot 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 // Directory listing template
dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html") dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html")
if err != nil { if err != nil {
...@@ -53,5 +60,6 @@ func init() { ...@@ -53,5 +60,6 @@ func init() {
listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{ listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{
"iconFromExt": iconFromExt, "iconFromExt": iconFromExt,
"urlEscape": urlEscape,
}).Parse(string(dirIndexBytes))) }).Parse(string(dirIndexBytes)))
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论