From 6dd18d3f589667992f362ae268fd5767b3e99aa1 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Sat, 6 Sep 2025 13:19:43 +0200 Subject: [PATCH] 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/.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 Reviewed-by: Lucas Co-authored-by: Robert Wolff Co-committed-by: Robert Wolff --- modules/markup/html.go | 6 +++++- modules/markup/html_test.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index aba287e0fd..58021f5cb5 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -557,9 +557,13 @@ func createCodeLink(href, content, class string) *html.Node { a.Attr = append(a.Attr, html.Attribute{Key: "class", Val: class}) } + unescaped, err := url.QueryUnescape(content) + if err != nil { + unescaped = content + } text := &html.Node{ Type: html.TextNode, - Data: content, + Data: unescaped, } code := &html.Node{ diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 3794673e82..11a6290ca3 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -91,6 +91,9 @@ func TestRender_Commits(t *testing.T) { test(sha[:14]+".", `

`+expected14+`.

`) test(sha[:14]+",", `

`+expected14+`,

`) test("["+sha[:14]+"]", `

[`+expected14+`]

`) + + fileStrangeChars := util.URLJoin(repo, "src", "commit", "eeb243c3395e1921c5d90e73bd739827251fc99d", "path", "to", "file%20%23.txt") + test(fileStrangeChars, `

eeb243c339/path/to/file #.txt

`) } func TestRender_CrossReferences(t *testing.T) {