Use net/url to escape paths in web-ui
License: MIT Signed-off-by: Adrian Ulrich <adrian@blinkenlights.ch>
Adrian Ulrich committed
Dec 17, 2015 at 09:31 UTC
ec7623bb817c881f659ab9fbad1c3f8b9e63394e
1 file changed
+8
core/corehttp/gateway_indexPage.go
+8
@@ -2,6 +2,7 @@ package corehttp
2
3
import (
4
"html/template"
5
+ "net/url"
6
"path"
7
"strings"
8
@@ -45,6 +46,12 @@ func init() {
46
return "ipfs-" + ext[1:] // slice of the first dot
47
}
48
49
+ // custom template-escaping function to escape a full path, including '#' and '?'
50
+ urlEscape := func(rawUrl string) string {
51
+ pathUrl := url.URL{Path: rawUrl}
52
+ return pathUrl.String()
53
+ }
54
+
55
// Directory listing template
56
dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html")
57
if err != nil {
@@ -53,5 +60,6 @@ func init() {
60
61
listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{
62
"iconFromExt": iconFromExt,
63
+ "urlEscape": urlEscape,
64
}).Parse(string(dirIndexBytes)))
65
}