mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
[MM-63607] Add length validation for LDAP user fields (#30596)
This commit is contained in:
parent
e544214f65
commit
494b570f3a
1 changed files with 20 additions and 0 deletions
|
|
@ -876,3 +876,23 @@ func SliceToMapKey(s ...string) map[string]any {
|
|||
|
||||
return m
|
||||
}
|
||||
|
||||
// LimitRunes limits the number of runes in a string to the given maximum.
|
||||
// It returns the potentially truncated string and a boolean indicating whether truncation occurred.
|
||||
func LimitRunes(s string, maxRunes int) (string, bool) {
|
||||
runes := []rune(s)
|
||||
if len(runes) > maxRunes {
|
||||
return string(runes[:maxRunes]), true
|
||||
}
|
||||
|
||||
return s, false
|
||||
}
|
||||
|
||||
// LimitBytes limits the number of bytes in a string to the given maximum.
|
||||
// It returns the potentially truncated string and a boolean indicating whether truncation occurred.
|
||||
func LimitBytes(s string, maxBytes int) (string, bool) {
|
||||
if len(s) > maxBytes {
|
||||
return s[:maxBytes], true
|
||||
}
|
||||
return s, false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue