fix: handle non-UTF8 bytes in git command output#477
Merged
altsem merged 1 commit intoaltsem:masterfrom Dec 15, 2025
Merged
Conversation
altsem
requested changes
Dec 13, 2025
Owner
altsem
left a comment
There was a problem hiding this comment.
There's a lot of irrelevant files in this PR
4b99c67 to
f42d5a3
Compare
altsem
previously approved these changes
Dec 13, 2025
Fixes altsem#458 Replace String::from_utf8() with String::from_utf8_lossy() to handle non-UTF8 bytes in git diff, status, and show output. Invalid UTF-8 sequences are now replaced with � (replacement character) instead of causing a crash. Changes: - src/git/mod.rs: Use from_utf8_lossy for diff/status/show commands - src/git/remote.rs: Use from_utf8_lossy for branch/remote names - src/git/parse/status/mod.rs: Use from_utf8_lossy for filename unescaping - src/tests/mod.rs: Add test for non-UTF8 diff display 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
f42d5a3 to
29dd4da
Compare
altsem
approved these changes
Dec 15, 2025
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.
Summary
Fixes #458
This PR fixes a crash that occurs when gitu encounters files with non-UTF8 bytes (e.g., ANSI escape codes or other binary content).
Changes
Replace
String::from_utf8()withString::from_utf8_lossy()throughout the codebase to gracefully handle invalid UTF-8 sequences. Invalid bytes are now replaced with � (replacement character) instead of causing a panic.Modified files:
src/git/mod.rs- Usefrom_utf8_lossyfor diff/status/show commandssrc/git/remote.rs- Usefrom_utf8_lossyfor branch/remote namessrc/git/parse/status/mod.rs- Usefrom_utf8_lossyfor filename unescapingTest coverage:
src/tests/stage.rs- Added 4 tests for non-UTF8 file handlingnon_utf8_in_unstaged_file- Display unstaged files with non-UTF8 contentnon_utf8_in_staged_file- Display staged files with non-UTF8 contentnon_utf8_in_modified_file- Display modified files with non-UTF8 contentnon_utf8_stage_and_unstage- Test staging operations on non-UTF8 filessrc/tests/log.rs- Added 1 test for non-UTF8 in commit displaynon_utf8_in_show_commit- Display commits containing non-UTF8 contentAll 302 tests pass ✅
Test plan
printf 'Text with non-UTF8: \xff\xfe\n' > test.txtcargo test --lib- all 302 tests pass🤖 Generated with Claude Code