diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-11-27 18:49:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-27 18:49:28 -0500 |
commit | 785a410936daff5db7fba07dc5735bd74dd158bb (patch) | |
tree | 1fb0619b42664e3d1d7607ba851c6c90008e8894 /model | |
parent | 6176bcff6977bda71f4fde10a52dde6d7d7ceb9a (diff) | |
download | chat-785a410936daff5db7fba07dc5735bd74dd158bb.tar.gz chat-785a410936daff5db7fba07dc5735bd74dd158bb.tar.bz2 chat-785a410936daff5db7fba07dc5735bd74dd158bb.zip |
Decrease plugin key value store table index name size (#7910)
Diffstat (limited to 'model')
-rw-r--r-- | model/plugin_key_value.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/model/plugin_key_value.go b/model/plugin_key_value.go index b25b4c170..ceb216c2a 100644 --- a/model/plugin_key_value.go +++ b/model/plugin_key_value.go @@ -5,6 +5,12 @@ package model import ( "net/http" + "unicode/utf8" +) + +const ( + KEY_VALUE_PLUGIN_ID_MAX_RUNES = 100 + KEY_VALUE_KEY_MAX_RUNES = 100 ) type PluginKeyValue struct { @@ -14,12 +20,12 @@ type PluginKeyValue struct { } func (kv *PluginKeyValue) IsValid() *AppError { - if len(kv.PluginId) == 0 { - return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", nil, "key="+kv.Key, http.StatusBadRequest) + if len(kv.PluginId) == 0 || utf8.RuneCountInString(kv.PluginId) > KEY_VALUE_PLUGIN_ID_MAX_RUNES { + return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest) } - if len(kv.Key) == 0 { - return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", nil, "key="+kv.Key, http.StatusBadRequest) + if len(kv.Key) == 0 || utf8.RuneCountInString(kv.Key) > KEY_VALUE_KEY_MAX_RUNES { + return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest) } return nil |