[MM-46644] Auto respond message (#20900)

Automatic Merge
Этот коммит содержится в:
Vishal
2022-10-07 18:32:11 +05:30
коммит произвёл GitHub
родитель 56fd8bf5cc
Коммит 6e9b808efd
3 изменённых файлов: 75 добавлений и 1 удалений

Просмотреть файл

@@ -34,8 +34,11 @@ const (
SYMBOLS = " !\"\\#$%&'()*+,-./:;<=>?@[]^_`|~"
BinaryParamKey = "MM_BINARY_PARAMETERS"
NoTranslation = "<untranslated>"
maxPropSizeBytes = 1024 * 1024
)
var ErrMaxPropSizeExceeded = fmt.Errorf("max prop size of %d exceeded", maxPropSizeBytes)
type StringInterface map[string]any
type StringArray []string
@@ -77,6 +80,14 @@ func (sa StringArray) Equals(input StringArray) bool {
// Value converts StringArray to database value
func (sa StringArray) Value() (driver.Value, error) {
sz := 0
for i := range sa {
sz += len(sa[i])
if sz > maxPropSizeBytes {
return nil, ErrMaxPropSizeExceeded
}
}
j, err := json.Marshal(sa)
if err != nil {
return nil, err
@@ -127,6 +138,15 @@ func (m *StringMap) Scan(value any) error {
func (m StringMap) Value() (driver.Value, error) {
ok := m[BinaryParamKey]
delete(m, BinaryParamKey)
sz := 0
for k := range m {
sz += len(k) + len(m[k])
if sz > maxPropSizeBytes {
return nil, ErrMaxPropSizeExceeded
}
}
buf, err := json.Marshal(m)
if err != nil {
return nil, err
@@ -182,6 +202,11 @@ func (si StringInterface) Value() (driver.Value, error) {
if err != nil {
return nil, err
}
if len(j) > maxPropSizeBytes {
return nil, ErrMaxPropSizeExceeded
}
// non utf8 characters are not supported https://mattermost.atlassian.net/browse/MM-41066
return string(j), err
}