1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-22 08:42:32 -05:00

trim whitespace of MilestoneName at creation/rename (#10017)

This commit is contained in:
6543 2020-01-27 17:23:21 +01:00 committed by zeripath
parent 51f6a7ab10
commit 88c3ccb897
2 changed files with 7 additions and 2 deletions

View file

@ -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
}
@ -272,6 +275,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},

View file

@ -161,7 +161,8 @@ func TestUpdateMilestone(t *testing.T) {
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{})
}