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>
This commit is contained in:
zeripath 2021-02-10 02:50:44 +00:00 committed by GitHub
parent 30f7ddb833
commit f82b1dd7c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 5 deletions

View file

@ -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:]...)