diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-01-07 18:20:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-07 18:20:22 +0800 |
commit | c5901b622dd5fae8da336b94150e63292489afed (patch) | |
tree | 1e7042bc2f4a402accf2305fc23dd00a22d2a360 /templates | |
parent | a43c7b81af2dad95149d2dc67edc141e1ab92d7c (diff) | |
download | gitea-c5901b622dd5fae8da336b94150e63292489afed.tar.gz gitea-c5901b622dd5fae8da336b94150e63292489afed.zip |
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)
Diffstat (limited to 'templates')
-rw-r--r-- | templates/base/head_opengraph.tmpl | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/templates/base/head_opengraph.tmpl b/templates/base/head_opengraph.tmpl index 19d924610c..f1f38999d2 100644 --- a/templates/base/head_opengraph.tmpl +++ b/templates/base/head_opengraph.tmpl @@ -17,7 +17,7 @@ {{else if or .PageIsDiff .IsViewFile}} <meta property="og:title" content="{{.Title}}"> <meta property="og:url" content="{{AppUrl}}{{.Link}}"> - {{if .PageIsDiff}} + {{if and .PageIsDiff .Commit}} {{- $commitMessageParts := StringUtils.Cut .Commit.Message "\n" -}} {{- $commitMessageBody := index $commitMessageParts 1 -}} {{- if $commitMessageBody -}} |