From b7f0dee4a75da7a2e8a2767af01ddea98caa43e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristopher=20Pinz=C3=B3n?= Date: Thu, 30 Dec 2021 05:54:15 -0500 Subject: [PATCH] escape windows return character (#4729) --- moto/sqs/models.py | 2 +- tests/test_sqs/test_sqs.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index d1b362bee..53e69b027 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -150,7 +150,7 @@ class Message(BaseModel): @property def body(self): - return escape(self._body) + return escape(self._body).replace('"', """).replace("\r", " ") def mark_sent(self, delay_seconds=None): self.sent_timestamp = int(unix_time_millis()) diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 54562bb13..17d84e5bf 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -3455,3 +3455,16 @@ def test_receive_message_again_preserves_attributes(): assert len(second_messages[0]["MessageAttributes"]) == 2 assert second_messages[0]["MessageAttributes"].get("Custom1") is not None assert second_messages[0]["MessageAttributes"].get("Custom2") is not None + + +@mock_sqs +def test_message_has_windows_return(): + sqs = boto3.resource("sqs", region_name="us-east-1") + queue = sqs.create_queue(QueueName=f"{str(uuid4())[0:6]}") + + message = "content:\rmessage_with line" + queue.send_message(MessageBody=message) + + messages = queue.receive_messages() + messages.should.have.length_of(1) + messages[0].body.should.match(message)