Fix for #748. Turn on autoescape for S3 templates. (#779)

This commit is contained in:
Tom V 2016-12-03 23:13:24 +00:00 committed by Steve Pulec
parent ee8e72766a
commit c54985a39f
4 changed files with 15 additions and 0 deletions

View File

@ -42,3 +42,4 @@ Moto is written by Steve Pulec with contributions from:
* [Pior Bastida](https://github.com/pior) * [Pior Bastida](https://github.com/pior)
* [Dustin J. Mitchell](https://github.com/djmitche) * [Dustin J. Mitchell](https://github.com/djmitche)
* [Jean-Baptiste Barth](https://github.com/jbbarth) * [Jean-Baptiste Barth](https://github.com/jbbarth)
* [Tom Viner](https://github.com/tomviner)

View File

@ -4,6 +4,8 @@ Moto Changelog
Latest Latest
------ ------
* Turn on variable escaping in templates for S3 XML documents
0.4.30 0.4.30
------ ------

View File

@ -38,6 +38,10 @@ class ResponseObject(_TemplateEnvironmentMixin):
super(ResponseObject, self).__init__() super(ResponseObject, self).__init__()
self.backend = backend self.backend = backend
@property
def should_autoescape(self):
return True
def all_buckets(self): def all_buckets(self):
# No bucket specified. Listing all buckets # No bucket specified. Listing all buckets
all_buckets = self.backend.get_all_buckets() all_buckets = self.backend.get_all_buckets()

View File

@ -989,6 +989,14 @@ def test_boto3_key_etag():
resp = s3.get_object(Bucket='mybucket', Key='steve') resp = s3.get_object(Bucket='mybucket', Key='steve')
resp['ETag'].should.equal('"d32bda93738f7e03adb22e66c90fbc04"') resp['ETag'].should.equal('"d32bda93738f7e03adb22e66c90fbc04"')
@mock_s3
def test_boto3_list_keys_xml_escaped():
s3 = boto3.client('s3', region_name='us-east-1')
s3.create_bucket(Bucket='mybucket')
key_name = 'Q&A.txt'
s3.put_object(Bucket='mybucket', Key=key_name, Body=b'is awesome')
resp = s3.list_objects_v2(Bucket='mybucket', Prefix=key_name)
assert resp['Contents'][0]['Key'] == key_name
@mock_s3 @mock_s3
def test_boto3_bucket_create(): def test_boto3_bucket_create():