mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-21 13:20:29 +00:00
chore: form binding trim space (#38978)
Use "binding:TrimSpace" instead of fragile IsEmptyString And fix a bug in locale's `HasKey`: it should also try the default language if current language doesn't have the translation key, a new test is added.
This commit is contained in:
@@ -87,6 +87,6 @@ type AuthenticationForm struct {
|
||||
SSPIAutoCreateUsers bool
|
||||
SSPIAutoActivateUsers bool
|
||||
SSPIStripDomainNames bool
|
||||
SSPISeparatorReplacement string `binding:"AlphaDashDot;MaxSize(5)"`
|
||||
SSPISeparatorReplacement string `binding:"TrimSpace;AlphaDashDot;MaxSize(5)"`
|
||||
SSPIDefaultLanguage string
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ type NewPackagistHookForm struct {
|
||||
// CreateIssueForm form for creating issue
|
||||
type CreateIssueForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
Title string `binding:"Required;MaxSize(255)"`
|
||||
Title string `binding:"TrimSpace;Required;MaxSize(255)"`
|
||||
AssigneeIDs string `form:"assignee_ids"`
|
||||
ReviewerIDs string `form:"reviewer_ids"`
|
||||
Ref string `form:"ref"`
|
||||
@@ -550,7 +550,7 @@ type GenerateReleaseNotesForm struct {
|
||||
// EditReleaseForm form for changing release
|
||||
type EditReleaseForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
Title string `form:"title" binding:"Required;MaxSize(255)"`
|
||||
Title string `form:"title" binding:"TrimSpace;Required;MaxSize(255)"`
|
||||
Content string `form:"content"`
|
||||
Draft string `form:"draft"`
|
||||
Prerelease bool `form:"prerelease"`
|
||||
@@ -558,20 +558,12 @@ type EditReleaseForm struct {
|
||||
}
|
||||
|
||||
type WikiEditForm struct {
|
||||
Title string
|
||||
middleware.FormDefaultValidator
|
||||
Title string `binding:"TrimSpace;Required"`
|
||||
Content string
|
||||
Message string
|
||||
}
|
||||
|
||||
func (f *WikiEditForm) Validate(ctx *middleware.ValidateContext, errs validation.BindingErrors) validation.BindingErrors {
|
||||
f.Title = strings.TrimSpace(f.Title)
|
||||
if f.Title == "" {
|
||||
errs = middleware.AddValidationError(errs, "title", ctx.Locale.TrString("repo.issues.new.title_empty"))
|
||||
}
|
||||
f.Message = strings.TrimSpace(f.Message)
|
||||
return errs
|
||||
}
|
||||
|
||||
// AddTimeManuallyForm form that adds spent time manually.
|
||||
type AddTimeManuallyForm struct {
|
||||
middleware.FormDefaultValidator
|
||||
|
||||
Reference in New Issue
Block a user