pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

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

Open wme-at-contact-de opened this issue 6 years ago • 1 comments

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?

wme-at-contact-de avatar Jul 23 '19 08:07 wme-at-contact-de

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.

futatuki avatar Nov 06 '22 20:11 futatuki