From 337eb9861a8fffcd1b5e718f113a20d0c65fa7ba Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sun, 23 Aug 2015 22:11:59 +0200 Subject: [PATCH] Fixes #1347 --- lib/core/common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 10012713e..a72c7cd75 100755 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1583,9 +1583,10 @@ def safeExpandUser(filepath): try: retVal = os.path.expanduser(filepath) - except UnicodeDecodeError: + except UnicodeError: _ = locale.getdefaultlocale() - retVal = getUnicode(os.path.expanduser(filepath.encode(_[1] if _ and len(_) > 1 else UNICODE_ENCODING))) + encoding = _[1] if _ and len(_) > 1 else UNICODE_ENCODING + retVal = getUnicode(os.path.expanduser(filepath.encode(encoding)), encoding=encoding) return retVal @@ -2115,7 +2116,7 @@ def getUnicode(value, encoding=None, noneToNull=False): elif isinstance(value, basestring): while True: try: - return unicode(value, encoding or kb.get("pageEncoding") or UNICODE_ENCODING) + return unicode(value, encoding or (kb.get("pageEncoding") if kb.get("originalPage") else None) or UNICODE_ENCODING) except UnicodeDecodeError, ex: try: return unicode(value, UNICODE_ENCODING)