Отвечать 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
@@ -30,6 +30,10 @@ func NewMessage(id, chatID, senderID uuid.UUID, text string) (Message, error) {
if utf8.RuneCountInString(text) > MaxTextCodePoints {
return Message{}, apperr.Invalid(fmt.Sprintf("text must be at most %d characters", MaxTextCodePoints))
}
// PostgreSQL text cannot hold U+0000.
if strings.ContainsRune(text, 0) {
return Message{}, apperr.Invalid("text must not contain the NUL character")
}
return Message{
ID: id,
ChatID: chatID,