Отвечать 400 и 401 вместо 500 на NUL и невалидный UTF-8 во входных данных

This commit is contained in:
2026-10-06 15:41:36 +03:00
parent 8f9252a5c1
commit 3001507ecb
10 changed files with 34 additions and 5 deletions
+4
View File
@@ -51,6 +51,10 @@ func New(id uuid.UUID, username, displayName string) (User, error) {
if utf8.RuneCountInString(displayName) > MaxDisplayNameCodePoints {
return User{}, apperr.Invalid(fmt.Sprintf("display_name must be at most %d characters", MaxDisplayNameCodePoints))
}
// PostgreSQL text cannot hold U+0000.
if strings.ContainsRune(displayName, 0) {
return User{}, apperr.Invalid("display_name must not contain the NUL character")
}
return User{
ID: id,
Username: username,