[MM-63607] Add length validation for LDAP user fields (#30596)

This commit is contained in:
Ben Schumacher 2025-11-04 10:02:18 +01:00 committed by GitHub
parent e544214f65
commit 494b570f3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
}