Gemini CLI PR fixes whitespace-only UTF-16/32 files being misdetected as non-empty

jesussamuel-byte · ghdev · 2026-10-13

A PR (#29722) to google-gemini/gemini-cli fixes an encoding bug in file emptiness detection: isEmpty() always decoded sampled bytes as UTF-8, but in UTF-16/UTF-32 a whitespace character spans 2 or 4 bytes, leaving NUL characters after decoding that trim() cannot strip. A whitespace-only file saved as UTF-16/32 with a BOM was therefore reported as non-empty, and validatePlanContent() would accept such blank plan files.

The fix introduces a decodeBOMContent helper that decodes bytes according to the BOM-detected encoding (UTF-8, UTF-16 LE/BE, UTF-32 LE/BE), and makes readFileWithEncoding() reuse the same helper so the two paths cannot drift apart. decodeUTF16BE now ignores an incomplete trailing code unit instead of throwing, preventing files with text from falling into the catch-all and being reported empty. Unchanged: only the first 1 KB is sampled; files without a BOM still decode as UTF-8. Tests cover all encodings with BOMs.

Original post →

More from coding & agent

coding & agent channel →