mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-18 07:53:04 +00:00
Slack webhook channel name cannot be empty or just contain an hashtag (#4786)
This commit is contained in:
parent
6e03390aa8
commit
be48397945
6 changed files with 69 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue