mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-22 23:03:47 +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:
@@ -13,7 +13,6 @@ import (
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/setting"
|
||||
api "gitea.dev/modules/structs"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/modules/web"
|
||||
"gitea.dev/services/context"
|
||||
"gitea.dev/services/convert"
|
||||
@@ -56,12 +55,6 @@ func NewWikiPage(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/repoArchivedError"
|
||||
|
||||
form := web.GetForm[*api.CreateWikiPageOptions](ctx)
|
||||
|
||||
if util.IsEmptyString(form.Title) {
|
||||
ctx.APIError(http.StatusBadRequest, "title is required")
|
||||
return
|
||||
}
|
||||
|
||||
wikiName := wiki_service.UserTitleToWebPath("", form.Title)
|
||||
|
||||
if len(form.Message) == 0 {
|
||||
|
||||
@@ -612,10 +612,6 @@ func EditProject(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
form := web.GetForm[*api.EditProjectOption](ctx)
|
||||
if form.Title != nil && util.IsEmptyString(*form.Title) {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "title must not be empty")
|
||||
return
|
||||
}
|
||||
opts := project_service.UpdateProjectOptions{
|
||||
Title: optional.FromPtr(form.Title),
|
||||
Description: optional.FromPtr(form.Description),
|
||||
@@ -1187,10 +1183,6 @@ func EditProjectColumn(ctx *context.APIContext) {
|
||||
|
||||
form := web.GetForm[*api.EditProjectColumnOption](ctx)
|
||||
if form.Title != nil {
|
||||
if util.IsEmptyString(*form.Title) {
|
||||
ctx.APIError(http.StatusUnprocessableEntity, "title must not be empty")
|
||||
return
|
||||
}
|
||||
column.Title = *form.Title
|
||||
}
|
||||
if form.Color != nil {
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/templates"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/modules/web"
|
||||
auth_service "gitea.dev/services/auth"
|
||||
"gitea.dev/services/auth/source/ldap"
|
||||
@@ -210,7 +209,7 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source {
|
||||
}
|
||||
|
||||
func parseSSPIConfig(ctx *context.Context, form forms.AuthenticationForm) (*sspi.Source, error) {
|
||||
if util.IsEmptyString(form.SSPISeparatorReplacement) {
|
||||
if form.SSPISeparatorReplacement == "" {
|
||||
ctx.Data["Err_SSPISeparatorReplacement"] = true
|
||||
return nil, errors.New(ctx.Locale.TrString("form.require_error", ctx.Locale.TrString("form.SSPISeparatorReplacement")))
|
||||
}
|
||||
|
||||
@@ -351,11 +351,6 @@ func NewIssuePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if util.IsEmptyString(form.Title) {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.new.title_empty"))
|
||||
return
|
||||
}
|
||||
|
||||
content := form.Content
|
||||
if filename := ctx.Req.Form.Get("template-file"); filename != "" {
|
||||
if template, err := issue_template.UnmarshalFromRepo(ctx, ctx.Repo.GitRepo, ctx.Repo.Repository.DefaultBranch, filename); err == nil {
|
||||
|
||||
@@ -1353,11 +1353,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if util.IsEmptyString(form.Title) {
|
||||
ctx.JSONError(ctx.Tr("repo.issues.new.title_empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// Check if a pull request already exists with the same head and base branch.
|
||||
pr, err := issues_model.GetUnmergedPullRequest(ctx, ci.HeadRepo.ID, repo.ID, ci.HeadRef.ShortName(), ci.BaseRef.ShortName(), issues_model.PullRequestFlowGithub)
|
||||
if err != nil && !issues_model.IsErrPullRequestNotExist(err) {
|
||||
|
||||
Reference in New Issue
Block a user