github.com/trigonella/mattermost-server@v5.11.1+incompatible/plugin/valid.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package plugin 5 6 import ( 7 "regexp" 8 "unicode/utf8" 9 ) 10 11 const ( 12 MinIdLength = 3 13 MaxIdLength = 190 14 ValidIdRegex = `^[a-zA-Z0-9-_\.]+$` 15 ) 16 17 // ValidId constrains the set of valid plugin identifiers: 18 // ^[a-zA-Z0-9-_\.]+ 19 var validId *regexp.Regexp 20 21 func init() { 22 validId = regexp.MustCompile(ValidIdRegex) 23 } 24 25 // IsValidId verifies that the plugin id has a minimum length of 3, maximum length of 190, and 26 // contains only alphanumeric characters, dashes, underscores and periods. 27 // 28 // These constraints are necessary since the plugin id is used as part of a filesystem path. 29 func IsValidId(id string) bool { 30 if utf8.RuneCountInString(id) < MinIdLength { 31 return false 32 } 33 34 if utf8.RuneCountInString(id) > MaxIdLength { 35 return false 36 } 37 38 return validId.MatchString(id) 39 }