libgit2 / libgit2/pygit2

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

オープン
#927 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
1.7k
フォーク
408
平均マージ
2日 57分
マージ済み PR(30日)
7

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

非 ASCII 文字を含むリポジトリパスを使って Python 3 の Windows 例を再現し、その後 repository.c、特に Repository_path__get__ と to_path の定義を調べます。Repository.path と Repository.workdir の両方を確認し、返されるパスが文書化されている回避策なしで元の文字を保持していることを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
git, python
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。