summaryrefslogtreecommitdiffstats
path: root/model/utils.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-04-22 21:52:03 +0900
committerHarrison Healey <harrisonmhealey@gmail.com>2017-04-22 08:52:03 -0400
commitecb10ed62fdff179e34f82b0ff2569da8390f4ad (patch)
treee2405ed87a31cca42275b98a76e1312c0a1867eb /model/utils.go
parente62afeace04e2abd23fa78a0a54e0a5d2e17e0b7 (diff)
downloadchat-ecb10ed62fdff179e34f82b0ff2569da8390f4ad.tar.gz
chat-ecb10ed62fdff179e34f82b0ff2569da8390f4ad.tar.bz2
chat-ecb10ed62fdff179e34f82b0ff2569da8390f4ad.zip
APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name (#6117)
* APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name * updated v3 deleteReaction endpoint * update parameter of app.DeleteReactionForPost() * update utils.IsValidAlphaNum, add utils.IsValidAlphaNumHyphenUnderscore, and add related tests
Diffstat (limited to 'model/utils.go')
-rw-r--r--model/utils.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/model/utils.go b/model/utils.go
index 6d8fafeea..cddf38166 100644
--- a/model/utils.go
+++ b/model/utils.go
@@ -297,7 +297,7 @@ var reservedName = []string{
func IsValidChannelIdentifier(s string) bool {
- if !IsValidAlphaNum(s, true) {
+ if !IsValidAlphaNumHyphenUnderscore(s, true) {
return false
}
@@ -308,22 +308,20 @@ func IsValidChannelIdentifier(s string) bool {
return true
}
-var validAlphaNumUnderscore = regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]+$`)
-var validAlphaNum = regexp.MustCompile(`^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$`)
+func IsValidAlphaNum(s string) bool {
+ validAlphaNum := regexp.MustCompile(`^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$`)
-func IsValidAlphaNum(s string, allowUnderscores bool) bool {
- var match bool
- if allowUnderscores {
- match = validAlphaNumUnderscore.MatchString(s)
- } else {
- match = validAlphaNum.MatchString(s)
- }
+ return validAlphaNum.MatchString(s)
+}
- if !match {
- return false
+func IsValidAlphaNumHyphenUnderscore(s string, withFormat bool) bool {
+ if withFormat {
+ validAlphaNumHyphenUnderscore := regexp.MustCompile(`^[a-z0-9]+([a-z\-\_0-9]+|(__)?)[a-z0-9]+$`)
+ return validAlphaNumHyphenUnderscore.MatchString(s)
}
- return true
+ validSimpleAlphaNumHyphenUnderscore := regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`)
+ return validSimpleAlphaNumHyphenUnderscore.MatchString(s)
}
func Etag(parts ...interface{}) string {