From ec7623bb817c881f659ab9fbad1c3f8b9e63394e Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Thu, 17 Dec 2015 09:31:16 +0100 Subject: [PATCH] Use net/url to escape paths in web-ui License: MIT Signed-off-by: Adrian Ulrich --- core/corehttp/gateway_indexPage.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/corehttp/gateway_indexPage.go b/core/corehttp/gateway_indexPage.go index 4485c84e6..366c99aca 100644 --- a/core/corehttp/gateway_indexPage.go +++ b/core/corehttp/gateway_indexPage.go @@ -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))) }