diff options
author | Lanre Adelowo <adelowomailbox@gmail.com> | 2018-09-10 15:31:08 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@users.noreply.github.com> | 2018-09-10 10:31:08 -0400 |
commit | be48397945c77748d412baad3493bb5bd1c95e2a (patch) | |
tree | d53dc2e78052588b6985400b762e994227183e76 /routers/utils/utils.go | |
parent | 6e03390aa8fa096206457962db1955d642860b57 (diff) | |
download | gitea-be48397945c77748d412baad3493bb5bd1c95e2a.tar.gz gitea-be48397945c77748d412baad3493bb5bd1c95e2a.zip |
Slack webhook channel name cannot be empty or just contain an hashtag (#4786)
Diffstat (limited to 'routers/utils/utils.go')
-rw-r--r-- | routers/utils/utils.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/routers/utils/utils.go b/routers/utils/utils.go index 6ead7d60e2..7c90fd7048 100644 --- a/routers/utils/utils.go +++ b/routers/utils/utils.go @@ -15,3 +15,22 @@ func RemoveUsernameParameterSuffix(name string) string { } return name } + +// IsValidSlackChannel validates a channel name conforms to what slack expects. +// It makes sure a channel name cannot be empty and invalid ( only an # ) +func IsValidSlackChannel(channelName string) bool { + switch len(strings.TrimSpace(channelName)) { + case 0: + return false + case 1: + // Keep default behaviour where a channel name is still + // valid without an # + // But if it contains only an #, it should be regarded as + // invalid + if channelName[0] == '#' { + return false + } + } + + return true +} |