mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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
This commit is contained in:
@@ -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>")
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user