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
+2 -1
View File
@@ -26,7 +26,7 @@ func (m *Messages) AddMessage(ctx context.Context, callerID, chatID, text string
INSERT INTO messages (chat_id, sender_id, text)
VALUES ($1, $2, $3)
RETURNING id::text, created_at`,
chatID, callerID, text,
chatID, callerID, encodeText(text),
).Scan(&msg.ID, &msg.CreatedAt)
if err != nil {
if isFKViolation(err) {
@@ -107,6 +107,7 @@ func (m *Messages) HistoryPage(ctx context.Context, chatID, cursor string, limit
out, err := pgx.CollectRows(rows, func(r pgx.CollectableRow) (domain.Message, error) {
var msg domain.Message
err := r.Scan(&msg.ID, &msg.ChatID, &msg.AuthorID, &msg.Text, &msg.CreatedAt)
msg.Text = decodeText(msg.Text)
msg.CreatedAt = msg.CreatedAt.UTC()
return msg, err
})