fix: path escape browse further URL (#10265)

- Resolves forgejo/forgejo#10214
- The renamed file can be any value, so escape it properly for usage in a URL path.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10265
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-11-30 02:58:15 +01:00 committed by Otto
parent c9e9494bff
commit 9bca858c42
2 changed files with 93 additions and 34 deletions

View file

@ -9,6 +9,7 @@ import (
"fmt"
"html/template"
"net/http"
"net/url"
"path"
"strings"
@ -272,7 +273,7 @@ func FileHistory(ctx *context.Context) {
for _, renames := range renamedFiles {
if renames[1] == fileName {
ctx.Data["OldFilename"] = renames[0]
ctx.Data["OldFilenameHistory"] = fmt.Sprintf("%s/commits/commit/%s/%s", ctx.Repo.RepoLink, oldestCommit.ID.String(), renames[0])
ctx.Data["OldFilenameHistory"] = fmt.Sprintf("%s/commits/commit/%s/%s", ctx.Repo.RepoLink, oldestCommit.ID.String(), url.PathEscape(renames[0]))
break
}
}