[Python-modules-commits] [python-git] 05/08: Description: Calling a git command (e.g. `show`) that contains invalid UTF-8 will cause a UnicodeDecodeError. Author: Barry Warsaw <barry at ubuntu.com> Bug: https://github.com/gitpython-developers/GitPython/issues/470

Barry Warsaw barry at moszumanska.debian.org
Wed Jun 15 10:56:32 UTC 2016


This is an automated email from the git hooks/post-receive script.

barry pushed a commit to branch master
in repository python-git.

commit d9fe5fffd84389eb8e8e5a74606eb7c8523877d4
Author: Barry Warsaw <barry at python.org>
Date:   Wed Jun 15 13:48:10 2016 +0300

    Description: Calling a git command (e.g. `show`) that contains invalid
     UTF-8 will cause a UnicodeDecodeError.
    Author: Barry Warsaw <barry at ubuntu.com>
    Bug: https://github.com/gitpython-developers/GitPython/issues/470
    
    Patch-Name: issue470-safe-decode.patch
---
 git/cmd.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/git/cmd.py b/git/cmd.py
index c29e348..955b25b 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -39,7 +39,8 @@ from git.compat import (
     PY3,
     bchr,
     # just to satisfy flake8 on py3
-    unicode
+    unicode,
+    safe_decode,
 )
 
 execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
@@ -688,12 +689,12 @@ class Git(LazyMixin):
             cmdstr = " ".join(command)
 
             def as_text(stdout_value):
-                return not output_stream and stdout_value.decode(defenc) or '<OUTPUT_STREAM>'
+                return not output_stream and safe_decode(stdout_value) or '<OUTPUT_STREAM>'
             # end
 
             if stderr_value:
                 log.info("%s -> %d; stdout: '%s'; stderr: '%s'",
-                         cmdstr, status, as_text(stdout_value), stderr_value.decode(defenc))
+                         cmdstr, status, as_text(stdout_value), safe_decode(stderr_value))
             elif stdout_value:
                 log.info("%s -> %d; stdout: '%s'", cmdstr, status, as_text(stdout_value))
             else:
@@ -707,11 +708,11 @@ class Git(LazyMixin):
                 raise GitCommandError(command, status, stderr_value)
 
         if isinstance(stdout_value, bytes) and stdout_as_string:  # could also be output_stream
-            stdout_value = stdout_value.decode(defenc)
+            stdout_value = safe_decode(stdout_value)
 
         # Allow access to the command's status code
         if with_extended_output:
-            return (status, stdout_value, stderr_value.decode(defenc))
+            return (status, stdout_value, safe_decode(stderr_value))
         else:
             return stdout_value
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-git.git



More information about the Python-modules-commits mailing list