10000 Incorrectly decoded strings in Repository.path and Repository.workdir when using Python 3 on Windows · Issue #927 · libgit2/pygit2 · GitHub
[go: up one dir, main page]

Skip to content

Incorrectly decoded strings in Repository.path and Repository.workdir when using Python 3 on Windows #927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wme-at-contact-de opened this issue Jul 23, 2019 · 1 comment

Comments

@wme-at-contact-de
Copy link

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?

@futatuki
Copy link
futatuki commented Nov 6, 2022

It seems that this issue is related to #537, which I commented, so I also write here.

If libgit2 on Windows returns a byte string encoded in UTF-8, it works correctly without extra encode/decode since Python >= 3.6 because the file system encoding on Windows is changed to 'utf-8' since then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0