aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Vasile <gabriel.vasile@email.com>2022-08-04 07:22:50 +0300
committerGitHub <noreply@github.com>2022-08-04 00:22:50 -0400
commitcf06e20c0ded4f2190e18d824be91f00f95e5f3e (patch)
treed7d73941750f862a3f869106488645162b78a51f
parent6c218f7a5c80d7446c0434a8a9bb22ab305dcf4d (diff)
downloadgitea-cf06e20c0ded4f2190e18d824be91f00f95e5f3e.tar.gz
gitea-cf06e20c0ded4f2190e18d824be91f00f95e5f3e.zip
Check webhooks slice length before calling xorm (#20642)
xorm.db.Insert errors for empty slices. Fixes: #20641 Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r--models/webhook/webhook.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go
index 1b79a414ad..478a6a29ff 100644
--- a/models/webhook/webhook.go
+++ b/models/webhook/webhook.go
@@ -399,6 +399,10 @@ func CreateWebhook(ctx context.Context, w *Webhook) error {
// CreateWebhooks creates multiple web hooks
func CreateWebhooks(ctx context.Context, ws []*Webhook) error {
+ // xorm returns err "no element on slice when insert" for empty slices.
+ if len(ws) == 0 {
+ return nil
+ }
for i := 0; i < len(ws); i++ {
ws[i].Type = strings.TrimSpace(ws[i].Type)
}