]> source.dussan.org Git - gitea.git/commitdiff
Avoid issue info panic (#29625)
authorwxiaoguang <wxiaoguang@gmail.com>
Wed, 6 Mar 2024 13:12:44 +0000 (21:12 +0800)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 13:12:44 +0000 (13:12 +0000)
Fix #29624

models/activities/action.go

index fcc97e387264de5b99c93cd3106425dba14172bd..36205eedd1f0394753729faa63a7c5c04ee346df 100644 (file)
@@ -393,10 +393,14 @@ func (a *Action) GetCreate() time.Time {
        return a.CreatedUnix.AsTime()
 }
 
-// GetIssueInfos returns a list of issues associated with
-// the action.
+// GetIssueInfos returns a list of associated information with the action.
 func (a *Action) GetIssueInfos() []string {
-       return strings.SplitN(a.Content, "|", 3)
+       // make sure it always returns 3 elements, because there are some access to the a[1] and a[2] without checking the length
+       ret := strings.SplitN(a.Content, "|", 3)
+       for len(ret) < 3 {
+               ret = append(ret, "")
+       }
+       return ret
 }
 
 // GetIssueTitle returns the title of first issue associated with the action.