mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-22 17:25:25 +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."""
|
"""Remove null bytes and invalid UTF-8 surrogates from text for PostgreSQL storage."""
|
||||||
if not isinstance(text, str):
|
if not isinstance(text, str):
|
||||||
return text
|
return text
|
||||||
# Remove null bytes - PostgreSQL cannot store \x00 in text fields
|
# Remove null bytes
|
||||||
text = text.replace("\x00", "")
|
text = text.replace("\x00", "").replace("\u0000", "")
|
||||||
# Remove invalid UTF-8 surrogate characters that can cause encoding errors
|
# Remove invalid UTF-8 surrogate characters that can cause encoding errors
|
||||||
# This handles cases where binary data or encoding issues introduced surrogates
|
# This handles cases where binary data or encoding issues introduced surrogates
|
||||||
try:
|
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):
|
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||||
pass
|
pass
|
||||||
return text
|
return text
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue