From fcae5ad49a3e68f9cae959add21803160f91185d Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:29:56 +0530 Subject: [PATCH] fix(file-ops): surrogatepass in bytes_written encode (review finding) Content that flowed through a surrogateescape decode (backend output via patch_replace) can carry lone surrogates; a strict encode raises UnicodeEncodeError where the old wc -c path could not. Mirrors the existing sha256 verification encode. --- tools/file_operations.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/file_operations.py b/tools/file_operations.py index 688bdcf8e539e..bd4a5f95de928 100644 --- a/tools/file_operations.py +++ b/tools/file_operations.py @@ -1593,8 +1593,11 @@ class ShellFileOperations(FileOperations): # Get bytes written — compute from the content we just wrote # (len(content.encode('utf-8')) matches wc -c for UTF-8) instead - # of spawning a ``wc -c`` subprocess. - bytes_written = len(content.encode('utf-8')) + # of spawning a ``wc -c`` subprocess. ``surrogatepass`` mirrors the + # sha256 verification block below: content that flowed through a + # surrogateescape decode (backend output via patch_replace) may + # carry lone surrogates a strict encode would reject. + bytes_written = len(content.encode('utf-8', 'surrogatepass')) # Post-write content verification (cheap, one shell call): compare # the on-disk sha256 to the intended content's hash. Production