Skip to content

Explicitly use utf-8 when decoding bytestrings #768

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

Merged
merged 1 commit into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygit2/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def orig_path(self):
if not path:
return None

return ffi.string(path).decode()
return ffi.string(path).decode('utf-8')


class Blame(object):
Expand Down
2 changes: 1 addition & 1 deletion pygit2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _from_found_config(fn):
buf = ffi.new('git_buf *', (ffi.NULL, 0))
err = fn(buf)
check_error(err, True)
cpath = ffi.string(buf.ptr).decode()
cpath = ffi.string(buf.ptr).decode('utf-8')
C.git_buf_free(buf)

return Config(cpath)
Expand Down
8 changes: 4 additions & 4 deletions pygit2/refspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def __init__(self, owner, ptr):
@property
def src(self):
"""Source or lhs of the refspec"""
return ffi.string(C.git_refspec_src(self._refspec)).decode()
return ffi.string(C.git_refspec_src(self._refspec)).decode('utf-8')

@property
def dst(self):
"""Destinaton or rhs of the refspec"""
return ffi.string(C.git_refspec_dst(self._refspec)).decode()
return ffi.string(C.git_refspec_dst(self._refspec)).decode('utf-8')

@property
def force(self):
Expand All @@ -58,7 +58,7 @@ def force(self):
@property
def string(self):
"""String which was used to create this refspec"""
return ffi.string(C.git_refspec_string(self._refspec)).decode()
return ffi.string(C.git_refspec_string(self._refspec)).decode('utf-8')

@property
def direction(self):
Expand All @@ -82,7 +82,7 @@ def _transform(self, ref, fn):
check_error(err)

try:
return ffi.string(buf.ptr).decode()
return ffi.string(buf.ptr).decode('utf-8')
finally:
C.git_buf_free(buf)

Expand Down
2 changes: 1 addition & 1 deletion pygit2/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _sideband_progress_cb(string, length, data):
return 0

try:
s = ffi.string(string, length).decode()
s = ffi.string(string, length).decode('utf-8')
progress(s)
except Exception as e:
self._stored_exception = e
Expand Down
2 changes: 1 addition & 1 deletion pygit2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
def strarray_to_strings(arr):
l = [None] * arr.count
for i in range(arr.count):
l[i] = ffi.string(arr.strings[i]).decode()
l[i] = ffi.string(arr.strings[i]).decode('utf-8')

return l

Expand Down