Permalink
Browse files

Merge pull request #2559 from kouk/nonasciiqueryargs

Support non-ascii unicode strings in _get_all_query_args. Fixes: #2558, #2559.
  • Loading branch information...
danielgtaylor committed Sep 2, 2014
2 parents 3ba380f + 258986e commit 069d04b96226034bea96f9ee4c56ce985e9e3d2c
Showing with 7 additions and 3 deletions.
  1. +3 −1 boto/s3/bucket.py
  2. +4 −2 tests/unit/s3/test_bucket.py
View
@@ -377,7 +377,9 @@ def _get_all_query_args(self, params, initial_query_string=''):
key = 'max-keys' key = 'max-keys'
if not isinstance(value, six.string_types + (six.binary_type,)): if not isinstance(value, six.string_types + (six.binary_type,)):
value = six.text_type(value) value = six.text_type(value)
if value != '': if not isinstance(value, six.binary_type):
value = value.encode('utf-8')
if value:
pairs.append(u'%s=%s' % ( pairs.append(u'%s=%s' % (
urllib.parse.quote(key), urllib.parse.quote(key),
urllib.parse.quote(value) urllib.parse.quote(value)
@@ -92,6 +92,8 @@ def test__get_all_query_args(self):
'foo': 'true', 'foo': 'true',
# Ensure Unicode chars get encoded. # Ensure Unicode chars get encoded.
'bar': '', 'bar': '',
# Ensure unicode strings with non-ascii characters get encoded
'baz': u'χ',
# Underscores are bad, m'kay? # Underscores are bad, m'kay?
'some_other': 'thing', 'some_other': 'thing',
# Change the variant of ``max-keys``. # Change the variant of ``max-keys``.
@@ -104,14 +106,14 @@ def test__get_all_query_args(self):
qa = bukket._get_all_query_args(multiple_params) qa = bukket._get_all_query_args(multiple_params)
self.assertEqual( self.assertEqual(
qa, qa,
'bar=%E2%98%83&foo=true&max-keys=0&some-other=thing' 'bar=%E2%98%83&baz=%CF%87&foo=true&max-keys=0&some-other=thing'
) )
# Multiple params with initial. # Multiple params with initial.
qa = bukket._get_all_query_args(multiple_params, 'initial=1') qa = bukket._get_all_query_args(multiple_params, 'initial=1')
self.assertEqual( self.assertEqual(
qa, qa,
'initial=1&bar=%E2%98%83&foo=true&max-keys=0&some-other=thing' 'initial=1&bar=%E2%98%83&baz=%CF%87&foo=true&max-keys=0&some-other=thing'
) )
@patch.object(S3Connection, 'head_bucket') @patch.object(S3Connection, 'head_bucket')

0 comments on commit 069d04b

Please sign in to comment.