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:
+13
-2
@@ -81,8 +81,19 @@ def route(rd, tier):
|
|||||||
return {"model":avail[0],"reason":"fallback"}
|
return {"model":avail[0],"reason":"fallback"}
|
||||||
|
|
||||||
def clean_unicode(text):
|
def clean_unicode(text):
|
||||||
if not isinstance(text, str): return text
|
if not isinstance(text, str):
|
||||||
return text.replace("\u2014","-").replace("\u2013","-").replace("\u2018",").replace(u2019,").replace("\u201c",').replace(u201d,').replace("\u2026","...").replace("\u00a0"," ")
|
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):
|
def clean_response(d):
|
||||||
if isinstance(d, dict): return {k: clean_response(v) for k,v in d.items()}
|
if isinstance(d, dict): return {k: clean_response(v) for k,v in d.items()}
|
||||||
|
|||||||
Reference in New Issue
Block a user