From b297b1410ccf8039dac922cc1c0419356d0dcd86 Mon Sep 17 00:00:00 2001 From: Oliver Jeeves Date: Tue, 13 Sep 2016 12:06:55 +0100 Subject: [PATCH] Stop stripping the trailing slash off keys listed from s3 buckets fixes #684 --- moto/s3bucket_path/utils.py | 2 +- tests/test_s3/test_s3.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/moto/s3bucket_path/utils.py b/moto/s3bucket_path/utils.py index aa7dc12f0..e10e64fb6 100644 --- a/moto/s3bucket_path/utils.py +++ b/moto/s3bucket_path/utils.py @@ -12,7 +12,7 @@ def bucket_name_from_url(url): def parse_key_name(path): - return "/".join(path.rstrip("/").split("/")[2:]) + return "/".join(path.split("/")[2:]) def is_delete_keys(request, path, bucket_name): diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 95a755ab1..5519f0c57 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -1076,3 +1076,20 @@ def test_website_configuration_xml(): bucket = conn.create_bucket('test-bucket') bucket.set_website_configuration_xml(TEST_XML) bucket.get_website_configuration_xml().should.equal(TEST_XML) + + +@mock_s3 +def test_key_with_trailing_slash_in_ordinary_calling_format(): + conn = boto.connect_s3( + 'access_key', + 'secret_key', + calling_format=boto.s3.connection.OrdinaryCallingFormat() + ) + bucket = conn.create_bucket('test_bucket_name') + + key_name = 'key_with_slash/' + + key = Key(bucket, key_name) + key.set_contents_from_string('some value') + + [k.name for k in bucket.get_all_keys()].should.contain(key_name)