Skip to content

Commit

Permalink
revert direct replacement for non-json, add dumped json message
Browse files Browse the repository at this point in the history
  • Loading branch information
baermat committed May 3, 2024
1 parent 499b836 commit e3489d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions localstack/aws/protocol/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,12 +1654,13 @@ def _node_to_string(self, root: Optional[ETree.ElementTree], mime_type: str) ->
# Undo the second escaping of the &
# Undo the second escaping of the carriage return (\r)
if mime_type == APPLICATION_JSON:
# At this point the json was already dumped and escaped, so we replace directly.
generated_string = generated_string.replace(r"__marker__\"__marker__", r"\"").replace(
"__marker__-r__marker__", r"\r"
)
else:
generated_string = generated_string.replace('__marker__"__marker__', '"').replace(
"__marker__-r__marker__", "\r"
generated_string = generated_string.replace('__marker__"__marker__', """).replace(
"__marker__-r__marker__", "
"
)

return to_bytes(generated_string)
Expand Down
8 changes: 5 additions & 3 deletions tests/aws/services/sqs/test_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,14 +1334,16 @@ def test_external_hostname_via_host_header(self, monkeypatch, sqs_create_queue,
kwargs = {"flags": re.MULTILINE | re.DOTALL}
assert re.match(rf".*<QueueUrl>\s*{url}/[^<]+</QueueUrl>.*", content, **kwargs)

@pytest.mark.parametrize(
argnames="json_body",
argvalues=['{"foo": "ba\rr", "foo2": "ba&quot;r&quot;"}', json.dumps('{"foo": "ba\rr"}')],
)
@markers.aws.validated
def test_marker_serialization_json_protocol(
self, sqs_create_queue, aws_client, aws_http_client_factory
self, sqs_create_queue, aws_client, aws_http_client_factory, json_body
):
queue_name = f"queue-{short_uid()}"
queue_url = sqs_create_queue(QueueName=queue_name)
# message_body = {"foo": "ba\rr", "foo2": "ba&quot;r&quot;"}
# aws_client.sqs.send_message(QueueUrl=queue_name, MessageBody=json.dumps(message_body))
message_body = '{"foo": "ba\rr", "foo2": "ba&quot;r&quot;"}'
aws_client.sqs.send_message(QueueUrl=queue_name, MessageBody=message_body)

Expand Down
6 changes: 6 additions & 0 deletions tests/aws/services/sqs/test_sqs.validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
"tests/aws/services/sqs/test_sqs.py::TestSqsProvider::test_list_queues": {
"last_validated_date": "2024-04-30T13:39:55+00:00"
},
"tests/aws/services/sqs/test_sqs.py::TestSqsProvider::test_marker_serialization_json_protocol[\"{\\\\\"foo\\\\\": \\\\\"ba\\\\rr\\\\\"}\"]": {
"last_validated_date": "2024-05-07T07:46:12+00:00"
},
"tests/aws/services/sqs/test_sqs.py::TestSqsProvider::test_marker_serialization_json_protocol[{\"foo\": \"ba\\rr\", \"foo2\": \"ba&quot;r&quot;\"}]": {
"last_validated_date": "2024-05-07T07:46:10+00:00"
},
"tests/aws/services/sqs/test_sqs.py::TestSqsProvider::test_marker_serialization_query_protocol": {
"last_validated_date": "2024-04-29T06:07:04+00:00"
},
Expand Down

0 comments on commit e3489d6

Please sign in to comment.