diff options
author | Daniel G. Taylor <dan@programmer-art.org> | 2014-09-02 10:50:02 -0700 |
---|---|---|
committer | Daniel G. Taylor <dan@programmer-art.org> | 2014-09-02 10:50:02 -0700 |
commit | 39cbcb5dbe5631f07ce829d15eaeedd1ecefab10 (patch) | |
tree | 4ed4f649f44161b1448e734d10b5126bad28b84e | |
parent | c1dd1fb4474883b0e09b86392620a981168dc961 (diff) | |
parent | 7f31661d15cd7a6182e9baeb829a7bf0006b8d62 (diff) | |
download | boto-39cbcb5dbe5631f07ce829d15eaeedd1ecefab10.tar.gz |
Merge pull request #2562 from kouk/bucketlisturlencoding
Avoid infinite loop with bucket listing and encoding_type='url'. Fixes #2562, #2561.
-rw-r--r-- | boto/s3/bucketlistresultset.py | 6 | ||||
-rw-r--r-- | tests/integration/s3/test_bucket.py | 19 |
2 files changed, 25 insertions, 0 deletions
diff --git a/boto/s3/bucketlistresultset.py b/boto/s3/bucketlistresultset.py index f0bc0602..ab9c65e4 100644 --- a/boto/s3/bucketlistresultset.py +++ b/boto/s3/bucketlistresultset.py @@ -19,6 +19,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +from boto.compat import urllib, six + def bucket_lister(bucket, prefix='', delimiter='', marker='', headers=None, encoding_type=None): """ @@ -34,6 +36,10 @@ def bucket_lister(bucket, prefix='', delimiter='', marker='', headers=None, yield k if k: marker = rs.next_marker or k.name + if marker and encoding_type == "url": + if isinstance(marker, six.text_type): + marker = marker.encode('utf-8') + marker = urllib.parse.unquote(marker) more_results= rs.is_truncated class BucketListResultSet(object): diff --git a/tests/integration/s3/test_bucket.py b/tests/integration/s3/test_bucket.py index f09d07ff..84951440 100644 --- a/tests/integration/s3/test_bucket.py +++ b/tests/integration/s3/test_bucket.py @@ -26,6 +26,7 @@ Some unit tests for the S3 Bucket """ +from mock import patch, Mock import unittest import time @@ -39,6 +40,7 @@ from boto.s3.lifecycle import Rule from boto.s3.acl import Grant from boto.s3.tagging import Tags, TagSet from boto.s3.website import RedirectLocation +from boto.compat import urllib class S3BucketTest (unittest.TestCase): @@ -86,6 +88,23 @@ class S3BucketTest (unittest.TestCase): self.assertEqual(element.name, expected.pop(0)) self.assertEqual(expected, []) + def test_list_with_url_encoding(self): + expected = ["α", "β", "γ"] + for key_name in expected: + key = self.bucket.new_key(key_name) + key.set_contents_from_string(key_name) + + # ensure bucket.list() still works by just + # popping elements off the front of expected. + orig_getall = self.bucket._get_all + getall = lambda *a, **k: orig_getall(*a, max_keys=2, **k) + with patch.object(self.bucket, '_get_all', getall): + rs = self.bucket.list(encoding_type="url") + for element in rs: + name = urllib.parse.unquote(element.name.encode('utf-8')) + self.assertEqual(name, expected.pop(0)) + self.assertEqual(expected, []) + def test_logging(self): # use self.bucket as the target bucket so that teardown # will delete any log files that make it into the bucket |