From 860489600a2e0862c73df5361ae8a86a622dfe05 Mon Sep 17 00:00:00 2001 From: XiaoXiao0221 <263113677+XiaoXiao0221@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:05:56 +0800 Subject: [PATCH] fix(cli): sanitize surrogate characters in handle_paste Prevents UTF-8 encoding crash when pasting text from Word or Google Docs, which may contain lone surrogate code points (U+D800-U+DFFF). Reuses existing _sanitize_surrogates() from run_agent module. --- cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli.py b/cli.py index b80ac2097..8490cc7cb 100644 --- a/cli.py +++ b/cli.py @@ -8695,6 +8695,9 @@ class HermesCLI: if _should_auto_attach_clipboard_image_on_paste(pasted_text) and self._try_attach_clipboard_image(): event.app.invalidate() if pasted_text: + # Sanitize surrogate characters (e.g. from Word/Google Docs paste) before writing + from run_agent import _sanitize_surrogates + pasted_text = _sanitize_surrogates(pasted_text) line_count = pasted_text.count('\n') buf = event.current_buffer if line_count >= 5 and not buf.text.strip().startswith('/'):