Отвечать 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
@@ -46,6 +46,10 @@ func NewChat(id uuid.UUID, title string) (Chat, error) {
if utf8.RuneCountInString(title) > MaxTitleCodePoints {
return Chat{}, apperr.Invalid(fmt.Sprintf("title must be at most %d characters", MaxTitleCodePoints))
}
// PostgreSQL text cannot hold U+0000.
if strings.ContainsRune(title, 0) {
return Chat{}, apperr.Invalid("title must not contain the NUL character")
}
return Chat{ID: id, Title: title, CreatedAt: ident.TimeOf(id)}, nil
}