Skip to content

Commit

Permalink
Check webhooks slice length before calling xorm (go-gitea#20642)
Browse files Browse the repository at this point in the history
xorm.db.Insert errors for empty slices. Fixes: go-gitea#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>
  • Loading branch information
4 people authored and Sysoev, Vladimir committed Aug 10, 2022
1 parent cf0fca3 commit 94e79ac
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions models/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 94e79ac

Please sign in to comment.