From 9aba690a60d17c1fc1c7ad82c0f499ff3cb5c202 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 15 Oct 2012 16:23:41 +0200 Subject: [PATCH] Patch for an Issue #203 --- lib/core/common.py | 10 ++++++++-- lib/core/option.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index eb56c0798..302978bff 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1962,7 +1962,7 @@ def extractErrorMessage(page): return retVal -def urldecode(value, encoding=None): +def urldecode(value, encoding=None, onlyPrintable=True): result = None if value: @@ -1972,7 +1972,13 @@ def urldecode(value, encoding=None): except ValueError: pass finally: - result = urllib.unquote_plus(value) + if onlyPrintable: + def _(match): + char = chr(ord(match.group(1).decode("hex"))) + return char if char in string.printable.replace("&", "") else match.group(0) + result = re.sub("%([0-9a-fA-F]{2})", _, value) + else: + result = urllib.unquote_plus(value) if isinstance(result, str): result = unicode(result, encoding or UNICODE_ENCODING, "replace") diff --git a/lib/core/option.py b/lib/core/option.py index cf6feb9a4..f6ffb97a7 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1339,10 +1339,10 @@ def __cleanupOptions(): if re.search(r'%[0-9a-f]{2}', conf.data, re.I): original = conf.data class _(unicode): pass - conf.data = _(urldecode(conf.data) if conf.data and urlencode(DEFAULT_GET_POST_DELIMITER, None) not in conf.data else conf.data) + conf.data = _(urldecode(conf.data)) setattr(conf.data, UNENCODED_ORIGINAL_VALUE, original) else: - conf.data = urldecode(conf.data) if conf.data and urlencode(DEFAULT_GET_POST_DELIMITER, None) not in conf.data else conf.data + conf.data = urldecode(conf.data) if conf.os: conf.os = conf.os.capitalize()