diff options
author | oliverpool <3864879+oliverpool@users.noreply.github.com> | 2022-08-11 17:48:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 17:48:23 +0200 |
commit | c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9 (patch) | |
tree | acccd4400733b5505a86ca668ceb4167119789fe /routers/utils | |
parent | 2b4d43dd4d7388ff73e99c143008ad4663142e61 (diff) | |
download | gitea-c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9.tar.gz gitea-c81b26b0e52f55fcdf94b50a14bca3dfc375e2a9.zip |
refactor webhook *NewPost (#20729)
* refactor webhook *NewPost
* remove empty values
* always show errs.Message
* remove utils.IsValidSlackChannel
* move IsValidSlackChannel to services/webhook package
* binding: handle empty Message case
* make IsValidSlackChannel more strict
Diffstat (limited to 'routers/utils')
-rw-r--r-- | routers/utils/utils.go | 19 | ||||
-rw-r--r-- | routers/utils/utils_test.go | 17 |
2 files changed, 0 insertions, 36 deletions
diff --git a/routers/utils/utils.go b/routers/utils/utils.go index f15bc1e62e..66eaa1d9ce 100644 --- a/routers/utils/utils.go +++ b/routers/utils/utils.go @@ -20,25 +20,6 @@ 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 -} - // SanitizeFlashErrorString will sanitize a flash error string func SanitizeFlashErrorString(x string) string { return strings.ReplaceAll(html.EscapeString(x), "\n", "<br>") diff --git a/routers/utils/utils_test.go b/routers/utils/utils_test.go index f49ed77b6f..42cf948e30 100644 --- a/routers/utils/utils_test.go +++ b/routers/utils/utils_test.go @@ -18,23 +18,6 @@ func TestRemoveUsernameParameterSuffix(t *testing.T) { assert.Equal(t, "", RemoveUsernameParameterSuffix("")) } -func TestIsValidSlackChannel(t *testing.T) { - tt := []struct { - channelName string - expected bool - }{ - {"gitea", true}, - {" ", false}, - {"#", false}, - {"gitea ", true}, - {" gitea", true}, - } - - for _, v := range tt { - assert.Equal(t, v.expected, IsValidSlackChannel(v.channelName)) - } -} - func TestIsExternalURL(t *testing.T) { setting.AppURL = "https://try.gitea.io/" type test struct { |