Intelligent encoding detection#4
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the hardcoded encoding fallback list with intelligent encoding detection using the chardet library to improve the robustness of diff file parsing across various encoding formats.
- Integrates
chardetlibrary for automatic encoding detection instead of trying a fixed list of encodings - Updates error messages to be more descriptive about parsing failures
- Refactors tests to focus on encoding support rather than Windows-specific issues
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/parser.py |
Replaces hardcoded encoding list with chardet-based detection and improved fallback handling |
src/chunker.py |
Updates error message to be more descriptive about empty diff files |
tests/test_encodings.py |
Adds comprehensive encoding tests including UTF-16 detection |
tests/test_windows_repro.py |
Removes Windows-specific test file |
pyproject.toml |
Adds chardet dependency |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
==========================================
+ Coverage 94.27% 94.29% +0.02%
==========================================
Files 7 7
Lines 419 421 +2
==========================================
+ Hits 395 397 +2
Misses 24 24 🚀 New features to boost your workflow:
|
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.
We currently try to parse using popular encoding formats (
"utf-8", "utf-8-sig", "cp1252", "latin-1"). This is very limiting since diffchunk is designed to be a foundational tool. Current design constrains us to a limited set of encoding for files. Leading to bugs such as #1This change uses https://github.com/chardet/chardet to smartly detect the encoding for a versatile parser. We only care about the text anyway, so we should offload that compute to a tool better suited.
This actually resolves #1