mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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:
		@@ -371,6 +371,10 @@ func NewFuncMap() []template.FuncMap {
 | 
			
		||||
		"RenderLabels": func(labels []*models.Label) template.HTML {
 | 
			
		||||
			html := `<span class="labels-list">`
 | 
			
		||||
			for _, label := range labels {
 | 
			
		||||
				// Protect against nil value in labels - shouldn't happen but would cause a panic if so
 | 
			
		||||
				if label == nil {
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
				html += fmt.Sprintf("<div class='ui label' style='color: %s; background-color: %s'>%s</div> ",
 | 
			
		||||
					label.ForegroundColor(), label.Color, RenderEmoji(label.Name))
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user