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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 31d036a28a19917dc7dd8c9cf66d5084dcbebde1
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-get-query-string-params
Merge into: launchpad:master
Diff against target: 19 lines (+7/-1)
1 file modified
lib/lp/services/webapp/servers.py (+7/-1)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398724@code.launchpad.net

Commit message

Fix get_query_string_params for Python 3

Description of the change

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.)

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/webapp/servers.py b/lib/lp/services/webapp/servers.py
2index d1e17fe..458d0e2 100644
3--- a/lib/lp/services/webapp/servers.py
4+++ b/lib/lp/services/webapp/servers.py
5@@ -531,7 +531,13 @@ def get_query_string_params(request):
6 if query_string is None:
7 query_string = ''
8
9- parsed_qs = parse_qs(query_string, keep_blank_values=True)
10+ # PEP-3333 specifies that strings must only contain codepoints
11+ # representable in ISO-8859-1.
12+ kwargs = {}
13+ if not six.PY2:
14+ kwargs['encoding'] = 'ISO-8859-1'
15+ kwargs['errors'] = 'replace'
16+ parsed_qs = parse_qs(query_string, keep_blank_values=True, **kwargs)
17 # Use BrowserRequest._decode() for decoding the received parameters.
18 decoded_qs = {}
19 for key, values in six.iteritems(parsed_qs):

Subscribers

People subscribed via source and target branches

to status/vote changes: