Skip to content

Commit

Permalink
Use unquote_plus instead of unquote
Browse files Browse the repository at this point in the history
Fixes aws/aws-cli#718

I'll also add an integ/unit test to the CLI repo to prevent
regressions in the future.
  • Loading branch information
jamesls committed Mar 27, 2014
1 parent 5e91699 commit 9f4b9ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions botocore/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class HTTPHeaders(http_client.HTTPMessage):
pass
from urllib.parse import quote
from urllib.parse import unquote
from urllib.parse import unquote_plus
from urllib.parse import urlsplit
from urllib.parse import urlunsplit
from urllib.parse import urljoin
Expand All @@ -33,7 +34,7 @@ class HTTPHeaders(http_client.HTTPMessage):
# In python3, unquote takes a str() object, url decodes it,
# then takes the bytestring and decodes it to utf-8.
# Python2 we'll have to do this ourself (see below).
unquote_str = unquote
unquote_str = unquote_plus

def set_socket_timeout(http_response, timeout):
"""Set the timeout of the socket from an HTTPResponse.
Expand All @@ -46,6 +47,7 @@ def set_socket_timeout(http_response, timeout):
else:
from urllib import quote
from urllib import unquote
from urllib import unquote_plus
from urlparse import urlsplit
from urlparse import urlunsplit
from urlparse import urljoin
Expand All @@ -68,7 +70,7 @@ def unquote_str(value, encoding='utf-8'):
# encode the string with the passed in encoding before trying to
# unquote it.
byte_string = value.encode(encoding)
return unquote(byte_string).decode(encoding)
return unquote_plus(byte_string).decode(encoding)

def set_socket_timeout(http_response, timeout):
"""Set the timeout of the socket from an HTTPResponse.
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ def test_unquote_normal(self):
# Note: decoded to unicode and utf-8 decoded as well.
# This would work in python2 and python3.
self.assertEqual(unquote_str(value), u'foo')

def test_unquote_with_spaces(self):
value = u'foo+bar'
# Note: decoded to unicode and utf-8 decoded as well.
# This would work in python2 and python3.
self.assertEqual(unquote_str(value), 'foo bar')

0 comments on commit 9f4b9ec

Please sign in to comment.