From 45bf3d0683bc3a0b9b87709ee09e39467bf53eb1 Mon Sep 17 00:00:00 2001 From: Konstantinos Koukopoulos Date: Tue, 26 Aug 2014 15:23:51 +0300 Subject: [PATCH 1/3] support non-ascii unicode strings in _get_all_query_args. Fixes: #2558 --- boto/s3/bucket.py | 2 ++ tests/unit/s3/test_bucket.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/boto/s3/bucket.py b/boto/s3/bucket.py index 34514078c2..4aac75267e 100644 --- a/boto/s3/bucket.py +++ b/boto/s3/bucket.py @@ -377,6 +377,8 @@ def _get_all_query_args(self, params, initial_query_string=''): key = 'max-keys' if not isinstance(value, six.string_types + (six.binary_type,)): value = six.text_type(value) + if not isinstance(value, six.binary_type): + value = value.encode('utf-8') if value != '': pairs.append(u'%s=%s' % ( urllib.parse.quote(key), diff --git a/tests/unit/s3/test_bucket.py b/tests/unit/s3/test_bucket.py index 3dc5f6e3ce..72e10ed2f9 100644 --- a/tests/unit/s3/test_bucket.py +++ b/tests/unit/s3/test_bucket.py @@ -92,6 +92,8 @@ def test__get_all_query_args(self): 'foo': 'true', # Ensure Unicode chars get encoded. 'bar': '☃', + # Ensure unicode strings with non-ascii characters get encoded + 'baz': u'χ', # Underscores are bad, m'kay? 'some_other': 'thing', # 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) self.assertEqual( 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. qa = bukket._get_all_query_args(multiple_params, 'initial=1') self.assertEqual( 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') From 31fbd86172befcedb5acaebb5486822a8951a3db Mon Sep 17 00:00:00 2001 From: Konstantinos Koukopoulos Date: Tue, 26 Aug 2014 17:32:14 +0300 Subject: [PATCH 2/3] fix comparison of query value for py3. Refs: #2558 --- boto/s3/bucket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boto/s3/bucket.py b/boto/s3/bucket.py index 4aac75267e..ec528ec3af 100644 --- a/boto/s3/bucket.py +++ b/boto/s3/bucket.py @@ -379,7 +379,7 @@ def _get_all_query_args(self, params, initial_query_string=''): value = six.text_type(value) if not isinstance(value, six.binary_type): value = value.encode('utf-8') - if value != '': + if value != six.binary_type(''): pairs.append(u'%s=%s' % ( urllib.parse.quote(key), urllib.parse.quote(value) From 258986e20a5143cdaab25ac1a9173f1648f97ac2 Mon Sep 17 00:00:00 2001 From: Konstantinos Koukopoulos Date: Tue, 26 Aug 2014 19:51:46 +0300 Subject: [PATCH 3/3] fix check for empty value thanks @methane --- boto/s3/bucket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boto/s3/bucket.py b/boto/s3/bucket.py index ec528ec3af..504f24f9bb 100644 --- a/boto/s3/bucket.py +++ b/boto/s3/bucket.py @@ -379,7 +379,7 @@ def _get_all_query_args(self, params, initial_query_string=''): value = six.text_type(value) if not isinstance(value, six.binary_type): value = value.encode('utf-8') - if value != six.binary_type(''): + if value: pairs.append(u'%s=%s' % ( urllib.parse.quote(key), urllib.parse.quote(value)