forked from mtusi2026/mtusi2026lab2
fixed a bug with NUL in strings
This commit is contained in:
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user