Skip to content

Commit

Permalink
Fix unicode encoding to replace non-ascii chars
Browse files Browse the repository at this point in the history
- Drops any unmapped non-ascii characters on non-utf8 systems
- Fixes #3131

Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Oct 30, 2018
1 parent 150ec74 commit 3381790
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/3131.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added additional logic for ignoring and replacing non-ascii characters when formatting console output on non-UTF-8 systems.
5 changes: 3 additions & 2 deletions pipenv/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,12 @@ def decode_output(output):
return output
try:
output = output.encode(DEFAULT_ENCODING)
except (AttributeError, UnicodeDecodeError):
except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):
if six.PY2:
output = unicode.translate(vistir.misc.to_text(output),
UNICODE_TO_ASCII_TRANSLATION_MAP)
else:
output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)
output = output.decode(DEFAULT_ENCODING)
output = output.encode(DEFAULT_ENCODING, "replace")
return vistir.misc.to_text(output, encoding=DEFAULT_ENCODING, errors="replace")
return output

0 comments on commit 3381790

Please sign in to comment.