mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-24 02:59:42 +08:00
Avoid unnecessary 500 panic when a commit doesn't exist (#28719)
In #26851, it assumed that `Commit` always exists when `PageIsDiff==true`. But for a 404 page, the `Commit` doesn't exist, so the following code would cause panic because nil value can't be passed as string parameter to `IsMultilineCommitMessage(string)` (or the StringUtils.Cut in later PRs)
This commit is contained in:
parent
a43c7b81af
commit
c5901b622d
@ -17,7 +17,7 @@
|
|||||||
{{else if or .PageIsDiff .IsViewFile}}
|
{{else if or .PageIsDiff .IsViewFile}}
|
||||||
<meta property="og:title" content="{{.Title}}">
|
<meta property="og:title" content="{{.Title}}">
|
||||||
<meta property="og:url" content="{{AppUrl}}{{.Link}}">
|
<meta property="og:url" content="{{AppUrl}}{{.Link}}">
|
||||||
{{if .PageIsDiff}}
|
{{if and .PageIsDiff .Commit}}
|
||||||
{{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}}
|
{{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}}
|
||||||
{{- $commitMessageBody := index $commitMessageParts 1 -}}
|
{{- $commitMessageBody := index $commitMessageParts 1 -}}
|
||||||
{{- if $commitMessageBody -}}
|
{{- if $commitMessageBody -}}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
@ -448,3 +449,12 @@ func TestGeneratedSourceLink(t *testing.T) {
|
|||||||
assert.Equal(t, "/user27/repo49/src/commit/aacbdfe9e1c4b47f60abe81849045fa4e96f1d75/test/test.txt", dataURL)
|
assert.Equal(t, "/user27/repo49/src/commit/aacbdfe9e1c4b47f60abe81849045fa4e96f1d75/test/test.txt", dataURL)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestViewCommit(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", "/user2/repo1/commit/0123456789012345678901234567890123456789")
|
||||||
|
req.Header.Add("Accept", "text/html")
|
||||||
|
resp := MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
assert.True(t, test.IsNormalPageCompleted(resp.Body.String()), "non-existing commit should render 404 page")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user