Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use net/url to escape paths in web-ui #2092

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions assets/bindata.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions core/corehttp/gateway_indexPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package corehttp

import (
"html/template"
"net/url"
"path"
"strings"

Expand Down Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks right to me

}

// Directory listing template
dirIndexBytes, err := assets.Asset(assetPath + "dir-index.html")
if err != nil {
Expand All @@ -53,5 +60,6 @@ func init() {

listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{
"iconFromExt": iconFromExt,
"urlEscape": urlEscape,
}).Parse(string(dirIndexBytes)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<div class="ipfs-icon ipfs-_blank">&nbsp;</div>
</td>
<td class="padding">
<a href="{{.BackLink}}">..</a>
<a href="{{ .BackLink | urlEscape}}">..</a>
</td>
<td></td>
</tr>
Expand All @@ -48,7 +48,7 @@
<div class="ipfs-icon {{iconFromExt .Name}}">&nbsp;</div>
</td>
<td>
<a href="{{ .Path }}">{{ .Name }}</a>
<a href="{{ .Path | urlEscape }}">{{ .Name }}</a>
</td>
<td>{{ .Size }}</td>
</tr>
Expand Down