Skip to content

Commit

Permalink
s3 key_name encoding should be variable (#5184)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon authored Jun 1, 2022
1 parent 34a98d2 commit b96eafb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions moto/s3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ def __init__(

self.s3_backend = s3_backend

@property
def safe_name(self):
return urllib.parse.quote(self.name, safe="")
def safe_name(self, encoding_type=None):
if encoding_type == "url":
return urllib.parse.quote(self.name, safe="")
return self.name

@property
def version_id(self):
Expand Down
4 changes: 2 additions & 2 deletions moto/s3/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ def _invalid_headers(self, url, headers):
{% endif %}
{% for key in result_keys %}
<Contents>
<Key>{{ key.safe_name }}</Key>
<Key>{{ key.safe_name(encoding_type) }}</Key>
<LastModified>{{ key.last_modified_ISO8601 }}</LastModified>
<ETag>{{ key.etag }}</ETag>
<Size>{{ key.size }}</Size>
Expand Down Expand Up @@ -2107,7 +2107,7 @@ def _invalid_headers(self, url, headers):
{% endif %}
{% for key in result_keys %}
<Contents>
<Key>{{ key.safe_name }}</Key>
<Key>{{ key.safe_name(encoding_type) }}</Key>
<LastModified>{{ key.last_modified_ISO8601 }}</LastModified>
<ETag>{{ key.etag }}</ETag>
<Size>{{ key.size }}</Size>
Expand Down

0 comments on commit b96eafb

Please sign in to comment.