1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 15:42:21 +08:00

Use net/url to escape paths in web-ui

License: MIT
Signed-off-by: Adrian Ulrich <adrian@blinkenlights.ch>
This commit is contained in:
Adrian Ulrich
2015-12-17 09:31:16 +01:00
committed by Stephen Whitmore
parent 9a923b4a1a
commit ec7623bb81

View File

@ -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)))
}