summaryrefslogtreecommitdiffstats
path: root/routers/repo/issue.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-02-10 02:50:44 +0000
committerGitHub <noreply@github.com>2021-02-10 10:50:44 +0800
commitf82b1dd7c384e0295530f2ded53c0938f7b2fc9b (patch)
tree60308c77693db06d01cdb5915e3264625752fa60 /routers/repo/issue.go
parent30f7ddb833adfe276a93c1a79e243b8d33bdd41e (diff)
downloadgitea-f82b1dd7c384e0295530f2ded53c0938f7b2fc9b.tar.gz
gitea-f82b1dd7c384e0295530f2ded53c0938f7b2fc9b.zip
Prevent adding nil label to .AddedLabels or .RemovedLabels (#14623)
* Prevent adding nil label to .AddedLabels or .RemovedLabels There are possibly a few old databases out there with malmigrated data that can cause panics with empty labels being migrated. This PR adds a few tests to prevent nil labels being added. Fix #14466 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add doctor command to remove the broken label comments Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers/repo/issue.go')
-rw-r--r--routers/repo/issue.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 3bc20839aa..1f57f2e9c8 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -2464,7 +2464,7 @@ func combineLabelComments(issue *models.Issue) {
if i == 0 || cur.Type != models.CommentTypeLabel ||
(prev != nil && prev.PosterID != cur.PosterID) ||
(prev != nil && cur.CreatedUnix-prev.CreatedUnix >= 60) {
- if cur.Type == models.CommentTypeLabel {
+ if cur.Type == models.CommentTypeLabel && cur.Label != nil {
if cur.Content != "1" {
cur.RemovedLabels = append(cur.RemovedLabels, cur.Label)
} else {
@@ -2474,10 +2474,12 @@ func combineLabelComments(issue *models.Issue) {
continue
}
- if cur.Content != "1" {
- prev.RemovedLabels = append(prev.RemovedLabels, cur.Label)
- } else {
- prev.AddedLabels = append(prev.AddedLabels, cur.Label)
+ if cur.Label != nil {
+ if cur.Content != "1" {
+ prev.RemovedLabels = append(prev.RemovedLabels, cur.Label)
+ } else {
+ prev.AddedLabels = append(prev.AddedLabels, cur.Label)
+ }
}
prev.CreatedUnix = cur.CreatedUnix
issue.Comments = append(issue.Comments[:i], issue.Comments[i+1:]...)