Slack webhook channel name cannot be empty or just contain an hashtag (#4786)

This commit is contained in:
Lanre Adelowo 2018-09-10 15:31:08 +01:00 committed by techknowlogick
parent 6e03390aa8
commit be48397945
6 changed files with 69 additions and 5 deletions

View file

@ -5,14 +5,16 @@
package utils
import (
api "code.gitea.io/sdk/gitea"
"encoding/json"
"net/http"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/routers/api/v1/convert"
"code.gitea.io/gitea/routers/utils"
api "code.gitea.io/sdk/gitea"
"github.com/Unknwon/com"
)
@ -119,8 +121,14 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
ctx.Error(422, "", "Missing config option: channel")
return nil, false
}
if !utils.IsValidSlackChannel(channel) {
ctx.Error(400, "", "Invalid slack channel name")
return nil, false
}
meta, err := json.Marshal(&models.SlackMeta{
Channel: channel,
Channel: strings.TrimSpace(channel),
Username: form.Config["username"],
IconURL: form.Config["icon_url"],
Color: form.Config["color"],