Skip to content

Commit 5e32b4c

Browse files
brosnerjoestump
authored andcommitted
use doseq in urllib.urlencode to correctly encode sequence values.
this is absolutely required for Client since querystring value that gets passed in via URI will pass through parse_qs and result in {"k": ["v1"]} for a single value.
1 parent 5166f26 commit 5e32b4c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

oauth2/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ def to_header(self, realm=''):
309309

310310
def to_postdata(self):
311311
"""Serialize as post data for a POST request."""
312-
return urllib.urlencode(self)
312+
# tell urlencode to deal with sequence values and map them correctly
313+
# to resulting querystring. for example self["k"] = ["v1", "v2"] will
314+
# result in 'k=v1&k=v2' and not k=%5B%27v1%27%2C+%27v2%27%5D
315+
return urllib.urlencode(self, True)
313316

314317
def to_url(self):
315318
"""Serialize as a URL for a GET request."""
@@ -325,7 +328,7 @@ def get_parameter(self, parameter):
325328
def get_normalized_parameters(self):
326329
"""Return a string that contains the parameters that must be signed."""
327330
items = [(k, v) for k, v in self.items() if k != 'oauth_signature']
328-
encoded_str = urllib.urlencode(sorted(items))
331+
encoded_str = urllib.urlencode(sorted(items), True)
329332
# Encode signature parameters per Oauth Core 1.0 protocol
330333
# spec draft 7, section 3.6
331334
# (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)

0 commit comments

Comments
 (0)