From 3381790ed13d360edb54c1699a606e67f92dee70 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 30 Oct 2018 11:44:17 -0400 Subject: [PATCH] Fix unicode encoding to replace non-ascii chars - Drops any unmapped non-ascii characters on non-utf8 systems - Fixes #3131 Signed-off-by: Dan Ryan --- news/3131.bugfix.rst | 1 + pipenv/_compat.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 news/3131.bugfix.rst diff --git a/news/3131.bugfix.rst b/news/3131.bugfix.rst new file mode 100644 index 0000000000..6eaa4bddff --- /dev/null +++ b/news/3131.bugfix.rst @@ -0,0 +1 @@ +Added additional logic for ignoring and replacing non-ascii characters when formatting console output on non-UTF-8 systems. diff --git a/pipenv/_compat.py b/pipenv/_compat.py index 6cc4c73216..d19bc51455 100644 --- a/pipenv/_compat.py +++ b/pipenv/_compat.py @@ -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