mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-07 23:09:32 +02:00
fix(repo): commit page fails to render unsigned commits with a different committer (#39381)
Since #39229 the commit page header dereferences `.Verification.CommittingUser` when the committer is not the author. `Verification` is `nil` for unsigned commits (see `repo.Diff`), so opening such a commit — a rebased or cherry-picked one, for example — logs a template error and the page comes out truncated: ``` Render failed: failed to render template: repo/commit_page, error: template error: builtin(bindata):repo/commit_page:138:22 : executing "repo/commit_page" at <.Verification.CommittingUser>: nil pointer evaluating interface {}.CommittingUser ``` This guards the access and adds an integration test that creates a commit with distinct author and committer identities and checks the page renders completely (the status stays 200 on a mid-render failure, so the test looks at the body). _The fix was worked out with help from an AI assistant; I reviewed and tested it myself._ --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
08149f9bec
commit
191287d8be
10 files changed
+73
-17
No files matched your search
@@ -21,7 +21,11 @@ import (
|
||||
"gitea.dev/services/context"
|
||||
)
|
||||
|
||||
const tplStatus500 templates.TplName = "status/500"
|
||||
const (
|
||||
tplStatus500 templates.TplName = "status/500"
|
||||
|
||||
PageInternalServerErrorMark = "status-page-500"
|
||||
)
|
||||
|
||||
func renderServerErrorPage(w http.ResponseWriter, req *http.Request, respCode int, tmpl templates.TplName, ctxData map[string]any, plainMsg string) {
|
||||
acceptsHTML := false
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRenderPanicErrorPage(t *testing.T) {
|
||||
t.Run("HTML", func(t *testing.T) {
|
||||
func TestRenderErrorPage(t *testing.T) {
|
||||
t.Run("PanicHTML", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := &http.Request{URL: &url.URL{}, Header: http.Header{"Accept": []string{"text/html"}}}
|
||||
req = req.WithContext(reqctx.NewRequestContextForTest(t))
|
||||
@@ -33,7 +33,7 @@ func TestRenderPanicErrorPage(t *testing.T) {
|
||||
// the different "footer" is the only way to know whether a page is fully rendered without error.
|
||||
assert.False(t, test.IsNormalPageCompleted(respContent))
|
||||
})
|
||||
t.Run("Plain", func(t *testing.T) {
|
||||
t.Run("ServiceUnavailablePlain", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := &http.Request{URL: &url.URL{}}
|
||||
req = req.WithContext(reqctx.NewRequestContextForTest(t))
|
||||
|
||||
Reference in new issue
Block a user