From 315026c2c55e8aa0dae21995eda35325fe273f0d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 28 Jan 2020 09:52:24 +0100 Subject: [PATCH] trim whitespace of MilestoneName at creation/rename (#10017) (#10034) --- models/issue_milestone.go | 4 ++++ models/issue_milestone_test.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/models/issue_milestone.go b/models/issue_milestone.go index f33ad19ad..38338e9be 100644 --- a/models/issue_milestone.go +++ b/models/issue_milestone.go @@ -6,6 +6,7 @@ package models import ( "fmt" + "strings" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -95,6 +96,8 @@ func NewMilestone(m *Milestone) (err error) { return err } + m.Name = strings.TrimSpace(m.Name) + if _, err = sess.Insert(m); err != nil { return err } @@ -268,6 +271,7 @@ func GetMilestones(repoID int64, page int, isClosed bool, sortType string) (Mile } func updateMilestone(e Engine, m *Milestone) error { + m.Name = strings.TrimSpace(m.Name) _, err := e.ID(m.ID).AllCols(). SetExpr("num_issues", builder.Select("count(*)").From("issue").Where( builder.Eq{"milestone_id": m.ID}, diff --git a/models/issue_milestone_test.go b/models/issue_milestone_test.go index 5b7d19aa4..00db3a907 100644 --- a/models/issue_milestone_test.go +++ b/models/issue_milestone_test.go @@ -158,10 +158,11 @@ func TestUpdateMilestone(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) milestone := AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone) - milestone.Name = "newMilestoneName" + milestone.Name = " newMilestoneName " milestone.Content = "newMilestoneContent" assert.NoError(t, UpdateMilestone(milestone)) - AssertExistsAndLoadBean(t, milestone) + milestone = AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone) + assert.EqualValues(t, "newMilestoneName", milestone.Name) CheckConsistencyFor(t, &Milestone{}) }