mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 07:57:30 +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:

committed by
Stephen Whitmore

parent
9a923b4a1a
commit
ec7623bb81
@ -2,6 +2,7 @@ package corehttp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -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() {
|
|||||||
|
|
||||||
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)))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user