fix: add length limit to discord webhook icon_url
This commit is contained in:
parent
b5b9cc1c38
commit
cf3ebab4ba
|
@ -2358,6 +2358,7 @@ settings.slack_icon_url = Icon URL
|
||||||
settings.slack_color = Color
|
settings.slack_color = Color
|
||||||
settings.discord_username = Username
|
settings.discord_username = Username
|
||||||
settings.discord_icon_url = Icon URL
|
settings.discord_icon_url = Icon URL
|
||||||
|
settings.discord_icon_url.exceeds_max_length = Icon URL must be less than or equal to 2048 characters
|
||||||
settings.event_desc = Trigger on:
|
settings.event_desc = Trigger on:
|
||||||
settings.event_push_only = Push events
|
settings.event_push_only = Push events
|
||||||
settings.event_send_everything = All events
|
settings.event_send_everything = All events
|
||||||
|
|
|
@ -14,6 +14,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"gitea.com/go-chi/binding"
|
||||||
|
|
||||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
|
@ -22,6 +24,7 @@ import (
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||||
|
gitea_context "code.gitea.io/gitea/services/context"
|
||||||
"code.gitea.io/gitea/services/forms"
|
"code.gitea.io/gitea/services/forms"
|
||||||
"code.gitea.io/gitea/services/webhook/shared"
|
"code.gitea.io/gitea/services/webhook/shared"
|
||||||
)
|
)
|
||||||
|
@ -31,13 +34,29 @@ type discordHandler struct{}
|
||||||
func (discordHandler) Type() webhook_module.HookType { return webhook_module.DISCORD }
|
func (discordHandler) Type() webhook_module.HookType { return webhook_module.DISCORD }
|
||||||
func (discordHandler) Icon(size int) template.HTML { return shared.ImgIcon("discord.png", size) }
|
func (discordHandler) Icon(size int) template.HTML { return shared.ImgIcon("discord.png", size) }
|
||||||
|
|
||||||
func (discordHandler) UnmarshalForm(bind func(any)) forms.WebhookForm {
|
type discordForm struct {
|
||||||
var form struct {
|
forms.WebhookCoreForm
|
||||||
forms.WebhookCoreForm
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
Username string
|
||||||
Username string
|
IconURL string
|
||||||
IconURL string
|
}
|
||||||
|
|
||||||
|
var _ binding.Validator = &discordForm{}
|
||||||
|
|
||||||
|
// Validate implements binding.Validator.
|
||||||
|
func (d *discordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||||
|
ctx := gitea_context.GetWebContext(req)
|
||||||
|
if len([]rune(d.IconURL)) > 2048 {
|
||||||
|
errs = append(errs, binding.Error{
|
||||||
|
FieldNames: []string{"IconURL"},
|
||||||
|
Message: ctx.Locale.TrString("repo.settings.discord_icon_url.exceeds_max_length"),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (discordHandler) UnmarshalForm(bind func(any)) forms.WebhookForm {
|
||||||
|
var form discordForm
|
||||||
bind(&form)
|
bind(&form)
|
||||||
|
|
||||||
return forms.WebhookForm{
|
return forms.WebhookForm{
|
||||||
|
|
Loading…
Reference in New Issue