diff options
author | Martin Kraft <martinkraft@gmail.com> | 2018-05-02 07:45:20 -0400 |
---|---|---|
committer | Martin Kraft <martinkraft@gmail.com> | 2018-05-02 07:45:20 -0400 |
commit | 7d5e85e4136b0e2e6cf902c48b186d99f0698d13 (patch) | |
tree | 84f7256de28eed0fd932f43532c218b385e09642 /plugin/valid.go | |
parent | f4dcb4edf2aafca85c9af631131a77888da24bc7 (diff) | |
parent | 529807c1ba0c6b5e697d95d35b46865e22b0e62a (diff) | |
download | chat-7d5e85e4136b0e2e6cf902c48b186d99f0698d13.tar.gz chat-7d5e85e4136b0e2e6cf902c48b186d99f0698d13.tar.bz2 chat-7d5e85e4136b0e2e6cf902c48b186d99f0698d13.zip |
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'plugin/valid.go')
-rw-r--r-- | plugin/valid.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugin/valid.go b/plugin/valid.go new file mode 100644 index 000000000..62c594a1a --- /dev/null +++ b/plugin/valid.go @@ -0,0 +1,32 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package plugin + +import ( + "regexp" + "unicode/utf8" +) + +const ( + MinIdLength = 3 + MaxIdLength = 190 +) + +var ValidId *regexp.Regexp + +func init() { + ValidId = regexp.MustCompile(`^[a-zA-Z0-9-_\.]+$`) +} + +func IsValidId(id string) bool { + if utf8.RuneCountInString(id) < MinIdLength { + return false + } + + if utf8.RuneCountInString(id) > MaxIdLength { + return false + } + + return ValidId.MatchString(id) +} |