fixed a bug with NUL in strings

This commit is contained in:
Нурлыгаянова Екатерина
2026-10-29 14:34:10 +03:00
parent 98ffd9ff45
commit 5021df4ea8
10 changed files with 177 additions and 36 deletions
+3 -1
View File
@@ -50,7 +50,7 @@ func (c *Chats) CreateChat(ctx context.Context, callerID, title string, memberID
INSERT INTO chats (title)
VALUES ($1)
RETURNING id::text, created_at`,
title,
encodeText(title),
).Scan(&chat.ID, &chat.CreatedAt)
if err != nil {
return domain.Chat{}, mapErr(err)
@@ -95,6 +95,7 @@ func (c *Chats) ChatByID(ctx context.Context, callerID, chatID string) (domain.C
}
return domain.Chat{}, err
}
chat.Title = decodeText(chat.Title)
chat.CreatedAt = chat.CreatedAt.UTC()
return chat, nil
}
@@ -134,6 +135,7 @@ func (c *Chats) ListChats(ctx context.Context, callerID, cursor string, limit in
out, err := pgx.CollectRows(rows, func(r pgx.CollectableRow) (domain.Chat, error) {
var ch domain.Chat
err := r.Scan(&ch.ID, &ch.Title, &ch.CreatedAt, &ch.MemberIDs)
ch.Title = decodeText(ch.Title)
ch.CreatedAt = ch.CreatedAt.UTC()
return ch, err
})