← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-get-query-string-params into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-get-query-string-params into launchpad:master.

Commit message:
Fix get_query_string_params for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398724

To be compatible with the expectations of both PEP-3333 and zope.publisher.browser.BrowserRequest._decode, we need to tell parse_qs to decode as ISO-8859-1.  (BrowserRequest._decode will then recode values using the request character set if necessary.)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-get-query-string-params into launchpad:master.
diff --git a/lib/lp/services/webapp/servers.py b/lib/lp/services/webapp/servers.py
index d1e17fe..458d0e2 100644
--- a/lib/lp/services/webapp/servers.py
+++ b/lib/lp/services/webapp/servers.py
@@ -531,7 +531,13 @@ def get_query_string_params(request):
     if query_string is None:
         query_string = ''
 
-    parsed_qs = parse_qs(query_string, keep_blank_values=True)
+    # PEP-3333 specifies that strings must only contain codepoints
+    # representable in ISO-8859-1.
+    kwargs = {}
+    if not six.PY2:
+        kwargs['encoding'] = 'ISO-8859-1'
+        kwargs['errors'] = 'replace'
+    parsed_qs = parse_qs(query_string, keep_blank_values=True, **kwargs)
     # Use BrowserRequest._decode() for decoding the received parameters.
     decoded_qs = {}
     for key, values in six.iteritems(parsed_qs):