Fix md5 unicode encode error#14
Conversation
|
Cursor Agent can help with this pull request. Just |
|
@cursor not sure if this problem is what I experienced, as the lines don't match the stacktrace. The full stacktrace is: Could you please check? |
|
I enhanced the
Learn more about Cursor Agents |
|
@cursor good, please bump version to 1.0.4. Also, please put the test files in a zip and open them during tests on CI, as seems these filenames are not allowed in MacOS and that could complicate the life of somebody who wants to clone the repo on a Mac. For reference, this is the error I'm getting while trying to checkout this branch on my mac: |
|
Skipping Bugbot: Bugbot is disabled for this repository |
|
@cursor ok, then please bump version to 1.0.4. Also, please put the test files in a zip and open them during tests on CI, as seems these filenames are not allowed in MacOS. |
|
I updated the project version and implemented a new test suite to address and verify fixes for
Learn more about Cursor Agents |
|
@cursor sorry, my mistake, please update the version to v1.0.2 instead of 1.0.4. |
|
I adjusted the project's version number to reflect a previous state or correction. This ensures the version accurately represents the current codebase.
Learn more about Cursor Agents |
|
@cursor I'm still unable to checkout the branch on my mac because of the test files you've added, please remove them or put them in a zipfile, and open it on the CI/CD at the build stage. |
|
I refactored the encoding test suite, renaming
Learn more about Cursor Agents |
- Fixed _get_hash function to use 'backslashreplace' instead of 'surrogateescape' - Added subdir encoding in all three processing paths in generate_hashes function - Updated version to 1.0.2 - Added comprehensive test suite that works on all platforms including macOS - Tests verify encoding functions work correctly with surrogate characters - Avoids creating files with surrogate characters to prevent filesystem issues Fixes: UnicodeEncodeError: 'utf-8' codec can't encode character '\udcfc' in position 101: surrogates not allowed
There was a problem hiding this comment.
Pull Request Overview
Fixes a UnicodeEncodeError in MD5 hash generation by changing string encoding from surrogateescape to backslashreplace for safer surrogate character handling.
- Changed encoding method in
_get_hashfunction from"surrogateescape"to"backslashreplace" - Added consistent subdir encoding throughout file output operations
- Added comprehensive test suite to verify the fix handles surrogate characters correctly
Reviewed Changes
Copilot reviewed 6 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| filehasher/init.py | Updated hash generation encoding and added subdir encoding for output consistency |
| filehasher/version.py | Bumped version to 1.0.2 |
| test_surrogate_encoding.py | Added comprehensive test suite for surrogate character encoding scenarios |
| test_surrogate_cases.json | Added JSON test case configuration (incomplete) |
| test�file/test.txt | Test file with surrogate character in path |
| test�file.txt | Test file with surrogate character in filename |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
954fd0b to
3134934
Compare
Fix
UnicodeEncodeErrorin MD5 hash generation by changing string encoding tobackslashreplacefor surrogate character handling.The
_get_hashfunction previously used"surrogateescape", which allowed surrogate characters to be encoded but led toUnicodeEncodeErrorwhen these characters were later processed or decoded. Switching to"backslashreplace"ensures that surrogate characters are safely represented as escape sequences, preventing encoding errors and aligning with the project's existing filename handling strategy.