Merge pull request #236 from joekiller/fix/sqs_xml_special_characters_in_body

Fix/sqs xml special characters in body
This commit is contained in:
Steve Pulec 2014-10-22 20:24:00 -04:00
commit 73d0deb47b
2 changed files with 21 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import base64
import hashlib
import time
import re
from xml.sax.saxutils import escape
from moto.core import BaseBackend
@ -19,7 +20,7 @@ DEFAULT_ACCOUNT_ID = 123456789012
class Message(object):
def __init__(self, message_id, body):
self.id = message_id
self.body = body
self._body = body
self.message_attributes = {}
self.receipt_handle = None
self.sender_id = DEFAULT_ACCOUNT_ID
@ -35,6 +36,10 @@ class Message(object):
body_md5.update(self.body.encode('utf-8'))
return body_md5.hexdigest()
@property
def body(self):
return escape(self._body)
def mark_sent(self, delay_seconds=None):
self.sent_timestamp = unix_time_millis()
if delay_seconds:

View File

@ -92,6 +92,21 @@ def test_send_message():
messages[1].get_body().should.equal(body_two)
@mock_sqs
def test_send_message_with_xml_characters():
conn = boto.connect_sqs('the_key', 'the_secret')
queue = conn.create_queue("test-queue", visibility_timeout=60)
queue.set_message_class(RawMessage)
body_one = '< & >'
queue.write(queue.new_message(body_one))
messages = conn.receive_message(queue, number_messages=1)
messages[0].get_body().should.equal(body_one)
@requires_boto_gte("2.28")
@mock_sqs
def test_send_message_with_attributes():