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.
More from coding & agent
- We tested 12 LLM classifiers — the new classifier hype is LARP — KlausCodes · 2026-10-23
- Dev builds ESP32 desk display showing Claude Code and Codex agent status via local Go helper — tonylook · 2026-10-23
- Let your agent read its own traces: AgentsView + history tool debugging workflow — dbreunig · 2026-10-23
- YC-backed Mireye launches land search API + MCP with 160M parcels for AI agents — ycombinator · 2026-10-23
- Testing 12 decision systems: the new LARP hype around classifiers — KlausCodes · 2026-10-23
- Monid launches 'Product Hunt for agents,' ranking tools by real agent calls — claudeai · 2026-10-23