From 52dbbb906804f36067ecbc8c89a00cdab545bdb2 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 18 Aug 2008 21:44:30 +0000 Subject: - Issue #3300: make urllib.parse.[un]quote() default to UTF-8. Code contributed by Matt Giuca. quote() now encodes the input before quoting, unquote() decodes after unquoting. There are new arguments to change the encoding and errors settings. There are also new APIs to skip the encode/decode steps. [un]quote_plus() are also affected. --- Lib/email/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Lib/email/utils.py') diff --git a/Lib/email/utils.py b/Lib/email/utils.py index e1d21f6a40..35275f6a42 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -219,7 +219,7 @@ def encode_rfc2231(s, charset=None, language=None): charset is given but not language, the string is encoded using the empty string for language. """ - s = urllib.parse.quote(s, safe='') + s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii') if charset is None and language is None: return s if language is None: @@ -271,7 +271,10 @@ def decode_params(params): # language specifiers at the beginning of the string. for num, s, encoded in continuations: if encoded: - s = urllib.parse.unquote(s) + # Decode as "latin-1", so the characters in s directly + # represent the percent-encoded octet values. + # collapse_rfc2231_value treats this as an octet sequence. + s = urllib.parse.unquote(s, encoding="latin-1") extended = True value.append(s) value = quote(EMPTYSTRING.join(value)) -- cgit v1.2.1