mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-29 22:25:59 +00:00
fix(ui): unescape file names in commit hash links (#9182)
### What? - `eeb243c339/path/to/file #.txt` instead of `eeb243c339/path/to/file%20%23.txt`, see [example on v13.next](https://v13.next.forgejo.org/mahlzahn/test/issues/3) ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9182 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Lucas <sclu1034@noreply.codeberg.org> Co-authored-by: Robert Wolff <mahlzahn@posteo.de> Co-committed-by: Robert Wolff <mahlzahn@posteo.de>
This commit is contained in:
parent
ac96bd1788
commit
6dd18d3f58
2 changed files with 8 additions and 1 deletions
|
@ -557,9 +557,13 @@ func createCodeLink(href, content, class string) *html.Node {
|
||||||
a.Attr = append(a.Attr, html.Attribute{Key: "class", Val: class})
|
a.Attr = append(a.Attr, html.Attribute{Key: "class", Val: class})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unescaped, err := url.QueryUnescape(content)
|
||||||
|
if err != nil {
|
||||||
|
unescaped = content
|
||||||
|
}
|
||||||
text := &html.Node{
|
text := &html.Node{
|
||||||
Type: html.TextNode,
|
Type: html.TextNode,
|
||||||
Data: content,
|
Data: unescaped,
|
||||||
}
|
}
|
||||||
|
|
||||||
code := &html.Node{
|
code := &html.Node{
|
||||||
|
|
|
@ -91,6 +91,9 @@ func TestRender_Commits(t *testing.T) {
|
||||||
test(sha[:14]+".", `<p>`+expected14+`.</p>`)
|
test(sha[:14]+".", `<p>`+expected14+`.</p>`)
|
||||||
test(sha[:14]+",", `<p>`+expected14+`,</p>`)
|
test(sha[:14]+",", `<p>`+expected14+`,</p>`)
|
||||||
test("["+sha[:14]+"]", `<p>[`+expected14+`]</p>`)
|
test("["+sha[:14]+"]", `<p>[`+expected14+`]</p>`)
|
||||||
|
|
||||||
|
fileStrangeChars := util.URLJoin(repo, "src", "commit", "eeb243c3395e1921c5d90e73bd739827251fc99d", "path", "to", "file%20%23.txt")
|
||||||
|
test(fileStrangeChars, `<p><a href="`+fileStrangeChars+`" rel="nofollow"><code>eeb243c339/path/to/file #.txt</code></a></p>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRender_CrossReferences(t *testing.T) {
|
func TestRender_CrossReferences(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue