From b96eafb3c3e4c2e40c4ca62a3b555a51296cc6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristopher=20Pinz=C3=B3n?= Date: Wed, 1 Jun 2022 16:26:27 -0500 Subject: [PATCH] s3 key_name encoding should be variable (#5184) --- moto/s3/models.py | 7 ++++--- moto/s3/responses.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/moto/s3/models.py b/moto/s3/models.py index 7cd3e1255..82fb4dbb4 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -154,9 +154,10 @@ class FakeKey(BaseModel): 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): diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 6f4addeee..d6eaa8105 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -2064,7 +2064,7 @@ S3_BUCKET_GET_RESPONSE = """ {% endif %} {% for key in result_keys %} - {{ key.safe_name }} + {{ key.safe_name(encoding_type) }} {{ key.last_modified_ISO8601 }} {{ key.etag }} {{ key.size }} @@ -2107,7 +2107,7 @@ S3_BUCKET_GET_RESPONSE_V2 = """ {% endif %} {% for key in result_keys %} - {{ key.safe_name }} + {{ key.safe_name(encoding_type) }} {{ key.last_modified_ISO8601 }} {{ key.etag }} {{ key.size }}