From ec0f9fac634e4518baca86953af3b84ea597773e Mon Sep 17 00:00:00 2001 From: "Abiba (pi)" Date: Sat, 16 May 2026 19:12:58 +0000 Subject: [PATCH] Fix: clean_unicode now uses chr()-based replacements + ASCII strip to prevent bash heredoc corruption. Emoji and all non-ASCII now fully stripped. --- router/router.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/router/router.py b/router/router.py index 34a2dd7..f47e0de 100644 --- a/router/router.py +++ b/router/router.py @@ -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()}