Decode line ranges using the requested text encoding - #195
Merged
fabiocaccamo merged 3 commits intoOct 1, 2026
Merged
fabiocaccamo merged 3 commits into
fabiocaccamo merged 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #195 +/- ##
=======================================
Coverage 98.48% 98.48%
=======================================
Files 13 13
Lines 793 794 +1
=======================================
+ Hits 781 782 +1
Misses 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This reverts commit b216841.
fabiocaccamo
approved these changes
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Fix encoding-aware line ranges in
read_file_lineswithout loading the whole file into memory.The default whole-file path decodes text before splitting lines, but the range path splits raw bytes at
0x0aand decodes each chunk independently. For UTF-16/UTF-32 this can split a code unit, produce garbage, or raiseUnicodeDecodeError. The binary line count also gives incorrect negative indexes for these encodings.strip_white=False, by settingnewline="\n".Minimal reproduction on the previous implementation:
Related issue
No issue filed; found while testing encoded line-range reads.
Validation
Windows, Python 3.12.10, using the project's existing pinned test environment:
python -X utf8 -m pytest tests --cov=fsutil --cov-report=term-missing --cov-fail-under=90: 258 passed, 3 existing Windows-specific skips, 98.36% coverage.python -X utf8 -m pre_commit run --all-files --show-diff-on-failure: all configured hooks passed.python -X utf8 -m mypy --install-types --non-interactive: passed, 13 source files.git diff --check: passed.The upstream multi-platform/Python-version CI matrix has not been run locally.
Checklist before requesting a review
AI assistance
AI tools assisted with reproducing the bug, implementing the minimal fix, writing tests, and preparing this description. No human review is claimed. No third-party code or assets were copied into this change.