diff options
author | Giteabot <teabot@gitea.io> | 2024-01-07 18:40:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-07 10:40:30 +0000 |
commit | 2399b4d483162e182fc09a3c7ffaf6359a0b4d90 (patch) | |
tree | dfa16f0a9d9bff8280f43e8e3dea5471ceb5b1d4 /templates | |
parent | ad2cb9863c063c7d016baccda6fcd7aeb5518aad (diff) | |
download | gitea-2399b4d483162e182fc09a3c7ffaf6359a0b4d90.tar.gz gitea-2399b4d483162e182fc09a3c7ffaf6359a0b4d90.zip |
Avoid unnecessary 500 panic when a commit doesn't exist (#28719) (#28721)
Backport #28719 by wxiaoguang
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)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
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 -}} |