fix: decode PowerShell 5.1 UTF-16LE read_file output - #688
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
ChangesUTF-16LE file reading
Priority: ➖ Normal — Schedule the PowerShell UTF-16LE compatibility fix because current decoding can introduce NUL characters and trigger PostgreSQL persistence errors. Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to UTF-16LE PowerShell files now return decoded, BOM-free text with preserved pagination behavior, including offsets and tail reads. The change is ready to merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes
read_filefor UTF-16LE text files produced by Windows PowerShell 5.1 redirection without changing the existing UTF-8/binary/PDF/image read paths.Fixes #610. Supersedes #621.
Problem
Windows PowerShell 5.1 writes redirected text with a
FF FEUTF-16LE BOM.read_filecurrently treats that text as UTF-8, which returns embedded\u0000characters and can break downstream persistence (22P05).Approach
TextFileHandlerwith a 2-byte probe.utf16ledecoding and skip the BOM.[Reading ...]status semantics.readFileInternal/editing behavior out of scope so this fix does not silently transcode edited UTF-16 files to UTF-8.Regression test
Adds
test/test-utf16-powershell-read.js, which writes the exact PowerShell-style bytes (FF FE+ UTF-16LE) and verifies:The new test fails on current
mainwithread_file must not return embedded NULsand passes with this change.Validation
npm test: 59/59 tests passed on macOS@('alpha','Rīga','gamma') *> file.txtproducedFF FE ...; this branch returned clean text with 0 NUL characters and the normal read-status headerCommit tested on Windows:
99f0062ba2c4f7cdeb964e3f9920153823912ad3.Summary by CodeRabbit