libgit2 / libgit2/pygit2

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

Open
#927 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.