Created
May 30, 2014 18:15
-
-
Save ahupp/daff4e7e2e4ebafbe14c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/magic.py b/magic.py | |
index cd5ff24..10685ac 100644 | |
--- a/magic.py | |
+++ b/magic.py | |
@@ -193,14 +193,15 @@ def coerce_filename(filename): | |
return None | |
# ctypes will implicitly convert unicode strings to bytes with | |
- # .encode('ascii'). A more useful default here is | |
- # getfilesystemencoding(). We need to leave byte-str unchanged. | |
+ # .encode('ascii'). If you use the filesystem encoding | |
+ # then you'll get inconsistent behavior (crashes) depending on the user's | |
+ # LANG environment variable | |
is_unicode = (sys.version_info[0] <= 2 and | |
isinstance(filename, unicode)) or \ | |
(sys.version_info[0] >= 3 and | |
isinstance(filename, str)) | |
if is_unicode: | |
- return filename.encode(sys.getfilesystemencoding()) | |
+ return filename.encode('utf-8') | |
else: | |
return filename | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment