Incorrectly decoded strings in Repository.path and Repository.workdir when using Python 3 on Windows
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 408
- Avg merge
- 2d 57m
- Merged PRs (30d)
- 7
Description
Example:
>import pygit2
>import sys
>r = pygit2.init_repository(r"C:\repösitory")
>r.path
'C:/repösitory/.git/' # this is a wrongly decoded path
>r.path.encode(sys.getfilesystemencoding()).decode("utf-8") # workaround
'C:/repösitory/.git/' # this looks right
Reproduced with "pygit2-0.28.2-cp35-cp35m-win32.whl".
The problem seems to be in "repository.c", function "Repository_path__get__":
return to_path(git_repository_path(self->repo));
The "to_path" function assumes that libgit2 returns a byte string with file system encoding:
#define to_path(x) to_unicode(x, Py_FileSystemDefaultEncoding, "strict")
But libgit2 actually returns a byte string encoded in UTF-8.
Maybe the behaviour of libgit2 has changed at some point?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Python 3 Windows example with a non-ASCII repository path, then inspect repository.c, especially Repository_path__get__ and the to_path definition. Check both Repository.path and Repository.workdir, and verify that returned paths preserve the original characters without the documented workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100