mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-22 09:15:21 +00:00
refac
This commit is contained in:
parent
48ccb1e170
commit
ae203d8952
1 changed files with 5 additions and 3 deletions
|
|
@ -377,12 +377,14 @@ def sanitize_text_for_db(text: str) -> str:
|
|||
"""Remove null bytes and invalid UTF-8 surrogates from text for PostgreSQL storage."""
|
||||
if not isinstance(text, str):
|
||||
return text
|
||||
# Remove null bytes - PostgreSQL cannot store \x00 in text fields
|
||||
text = text.replace("\x00", "")
|
||||
# Remove null bytes
|
||||
text = text.replace("\x00", "").replace("\u0000", "")
|
||||
# Remove invalid UTF-8 surrogate characters that can cause encoding errors
|
||||
# This handles cases where binary data or encoding issues introduced surrogates
|
||||
try:
|
||||
text = text.encode("utf-8", errors="surrogatepass").decode("utf-8", errors="ignore")
|
||||
text = text.encode("utf-8", errors="surrogatepass").decode(
|
||||
"utf-8", errors="ignore"
|
||||
)
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
pass
|
||||
return text
|
||||
|
|
|
|||
Loading…
Reference in a new issue