diff --git a/lib/core/common.py b/lib/core/common.py index 872b949fd..dc3b6cbfc 100755 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -14,6 +14,7 @@ import hashlib import httplib import inspect import json +import locale import logging import ntpath import os @@ -1558,6 +1559,22 @@ def normalizePath(filepath): return retVal +def safeExpandUser(filepath): + """ + Patch for a Python Issue18171 (http://bugs.python.org/issue18171) + """ + + retVal = filepath + + try: + retVal = os.path.expanduser(filepath) + except UnicodeDecodeError: + _ = locale.getdefaultlocale() + retVal = getUnicode(os.path.expanduser(filepath.encode(_[1] if _ and len(_) > 1 else UNICODE_ENCODING))) + + print retVal + return retVal + def safeStringFormat(format_, params): """ Avoids problems with inappropriate string format strings diff --git a/lib/core/option.py b/lib/core/option.py index eb42dc8d5..860eddddd 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -52,6 +52,7 @@ from lib.core.common import readCachedFileContent from lib.core.common import readInput from lib.core.common import resetCookieJar from lib.core.common import runningAsAdmin +from lib.core.common import safeExpandUser from lib.core.common import sanitizeStr from lib.core.common import setOptimize from lib.core.common import setPaths @@ -496,7 +497,7 @@ def _setRequestFromFile(): addedTargetUrls = set() - conf.requestFile = os.path.expanduser(conf.requestFile) + conf.requestFile = safeExpandUser(conf.requestFile) infoMsg = "parsing HTTP request from '%s'" % conf.requestFile logger.info(infoMsg) @@ -619,7 +620,7 @@ def _setBulkMultipleTargets(): if not conf.bulkFile: return - conf.bulkFile = os.path.expanduser(conf.bulkFile) + conf.bulkFile = safeExpandUser(conf.bulkFile) infoMsg = "parsing multiple targets list from '%s'" % conf.bulkFile logger.info(infoMsg) @@ -1268,7 +1269,7 @@ def _setHTTPAuthentication(): debugMsg = "setting the HTTP(s) authentication PEM private key" logger.debug(debugMsg) - _ = os.path.expanduser(conf.authPrivate) + _ = safeExpandUser(conf.authPrivate) checkFile(_) authHandler = HTTPSPKIAuthHandler(_) @@ -1475,7 +1476,7 @@ def _cleanupOptions(): for key, value in conf.items(): if value and any(key.endswith(_) for _ in ("Path", "File")): - conf[key] = os.path.expanduser(value) + conf[key] = safeExpandUser(value) if conf.testParameter: conf.testParameter = urldecode(conf.testParameter)