ofek / userpath

Cross-platform tool for adding locations to the user PATH, no elevated privileges required!
MIT License
151 stars 20 forks source link

Encode stdout from subprocess.Popen command using locale's encoding. #37

Closed itsayellow closed 3 years ago

itsayellow commented 3 years ago

Closes #35 .

This modifies userpath.utils.get_flat_output() to encode the result from stdout using the locale's preferred encoding (presumably what is being used to encode the output of the subprocess.Popen stdout). We use locale.getpreferredencoding(False) to accomplish this to ensure maximum compatibility back to Python 2.7.

Previously the code used hard-coded "utf-8" encoding to decode stdout, and this may not be correct for some platforms, possibly resulting in a UnicodeError.