diff --git a/moto/s3/utils.py b/moto/s3/utils.py index 7dd0accc..19b0cfdf 100644 --- a/moto/s3/utils.py +++ b/moto/s3/utils.py @@ -8,8 +8,8 @@ bucket_name_regex = re.compile("(.+).s3.amazonaws.com") def bucket_name_from_url(url): domain = urlparse.urlparse(url).netloc - # If 'www' prefixed, strip it. - domain = domain.replace("www.", "") + if domain.startswith('www.'): + domain = domain[4:] if 'amazonaws.com' in domain: bucket_result = bucket_name_regex.search(domain) diff --git a/tests/test_s3/test_s3_utils.py b/tests/test_s3/test_s3_utils.py index 5b03d61f..cb8bd8b8 100644 --- a/tests/test_s3/test_s3_utils.py +++ b/tests/test_s3/test_s3_utils.py @@ -7,7 +7,7 @@ def test_base_url(): def test_localhost_bucket(): - expect(bucket_name_from_url('https://foobar.localhost:5000/abc')).should.equal("foobar") + expect(bucket_name_from_url('https://wfoobar.localhost:5000/abc')).should.equal("wfoobar") def test_localhost_without_bucket():