FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: handle paths with non-utf-8 bytes by abraemer · Pull Request #91 · aboutcode-org/commoncode · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion src/commoncode/resource.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def _get_resource_cache_location(self, path, create_dirs=False):
path = clean_path(path)

# for the cached file name, we use an md5 of the path to avoid things being too long
resid = str(md5(path.encode("utf-8")).hexdigest())
resid = str(md5(path.encode("utf-8", "surrogateescape")).hexdigest())
cache_sub_dir, cache_file_name = resid[-2:], resid

parent = join(self.cache_dir, cache_sub_dir)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_resource.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ def test_codebase_cache_default(self):
child_2 = codebase.get_resource(path=child.path)
assert child_2 == child

def test_codebase_cache_handles_non_utf8_path(self):
test_codebase = self.get_test_loc("resource/cache2")
codebase = Codebase(test_codebase)
codebase._get_resource_cache_location("resource/cache2/\udce9", create_dirs=True)

def test_codebase_cache_all_in_memory(self):
test_codebase = self.get_test_loc("resource/cache2")
codebase = Codebase(test_codebase, max_in_memory=0)
Expand Down

Back | FazBrowse Home | New Git URL