Fix: clean_unicode now uses chr()-based replacements + ASCII strip to prevent bash heredoc corruption. Emoji and all non-ASCII now fully stripped.

This commit is contained in:
Abiba (pi)
2026-05-16 19:12:58 +00:00
parent 3d42ea4767
commit ec0f9fac63
+13 -2
View File
@@ -81,8 +81,19 @@ def route(rd, tier):
return {"model":avail[0],"reason":"fallback"}
def clean_unicode(text):
if not isinstance(text, str): return text
return text.replace("\u2014","-").replace("\u2013","-").replace("\u2018",").replace(u2019,").replace("\u201c",').replace(u201d,').replace("\u2026","...").replace("\u00a0"," ")
if not isinstance(text, str):
return text
# Replace common Unicode punctuation with ASCII equivalents
text = text.replace(chr(0x2014), "-")
text = text.replace(chr(0x2013), "-")
text = text.replace(chr(0x2018), "'")
text = text.replace(chr(0x2019), "'")
text = text.replace(chr(0x201C), '"')
text = text.replace(chr(0x201D), '"')
text = text.replace(chr(0x2026), "...")
text = text.replace(chr(0x00A0), " ")
# Strip ALL remaining non-ASCII (emoji, symbols)
return text.encode("ascii", "ignore").decode("ascii")
def clean_response(d):
if isinstance(d, dict): return {k: clean_response(v) for k,v in d.items()}