Merge pull request 'fix: validate title length when updating an issue' (#4809) from thilinajayanath/forgejo:validate-issue-title-update into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4809
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Otto 2024-08-21 12:55:26 +00:00
commit c20c534b90
2 changed files with 75 additions and 3 deletions

View file

@ -57,6 +57,8 @@ import (
issue_service "code.gitea.io/gitea/services/issue"
pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository"
"gitea.com/go-chi/binding"
)
const (
@ -2218,10 +2220,20 @@ func UpdateIssueTitle(ctx *context.Context) {
ctx.Error(http.StatusForbidden)
return
}
title := ctx.FormTrim("title")
if len(title) == 0 {
ctx.Error(http.StatusNoContent)
if util.IsEmptyString(title) {
ctx.Error(http.StatusBadRequest, "Title cannot be empty or spaces")
return
}
// Creating a CreateIssueForm with the title so that we can validate the max title length
i := forms.CreateIssueForm{
Title: title,
}
bindingErr := binding.RawValidate(i)
if bindingErr.Has(binding.ERR_MAX_SIZE) {
ctx.Error(http.StatusBadRequest, "Title cannot be longer than 255 characters")
return
}