fix: preserve Unicode NUL in messages and metadata
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -62,7 +62,7 @@ def _user(row: Row) -> User:
|
||||
return User(
|
||||
id=row.id,
|
||||
username=row.username,
|
||||
display_name=row.display_name,
|
||||
display_name=row.display_name.decode("utf-8"),
|
||||
created_at=row.created_at,
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ def _user(row: Row) -> User:
|
||||
def _chat(row: Row) -> Chat:
|
||||
return Chat(
|
||||
id=row.id,
|
||||
title=row.title,
|
||||
title=row.title.decode("utf-8"),
|
||||
member_ids=tuple(row.member_ids),
|
||||
created_at=row.created_at,
|
||||
)
|
||||
@@ -81,7 +81,7 @@ def _message(row: Row) -> Message:
|
||||
id=row.id,
|
||||
chat_id=row.chat_id,
|
||||
sender_id=row.sender_id,
|
||||
text=row.text,
|
||||
text=row.text.decode("utf-8"),
|
||||
created_at=row.created_at,
|
||||
)
|
||||
|
||||
@@ -116,7 +116,7 @@ class PostgresStorage:
|
||||
.values(
|
||||
id=user.id,
|
||||
username=user.username,
|
||||
display_name=user.display_name,
|
||||
display_name=user.display_name.encode("utf-8"),
|
||||
password_hash=password_hash,
|
||||
created_at=user.created_at,
|
||||
)
|
||||
@@ -211,7 +211,9 @@ class PostgresStorage:
|
||||
raise InvalidMembers
|
||||
await connection.execute(
|
||||
insert(chats).values(
|
||||
id=chat.id, title=chat.title, created_at=chat.created_at
|
||||
id=chat.id,
|
||||
title=chat.title.encode("utf-8"),
|
||||
created_at=chat.created_at,
|
||||
),
|
||||
)
|
||||
await connection.execute(
|
||||
@@ -280,7 +282,8 @@ class PostgresStorage:
|
||||
id=message.id,
|
||||
chat_id=message.chat_id,
|
||||
sender_id=message.sender_id,
|
||||
text=message.text,
|
||||
# PostgreSQL text не допускает U+0000; bytea сохраняет UTF-8 целиком.
|
||||
text=message.text.encode("utf-8"),
|
||||
created_at=message.created_at,
|
||||
)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user