Permalink
Browse files

Prevent InvalidXmlError exceptions by properly escaping IM notifications

  • Loading branch information...
1 parent 093e507 commit c681dba9d309f19b9c79996f05f59bba5e25c8f1 @lovett committed Jul 19, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 appengine/tasks.py
View
6 appengine/tasks.py
@@ -5,6 +5,7 @@
from google.appengine.api import xmpp
from google.appengine.api import urlfetch
from google.appengine.ext.webapp.util import run_wsgi_app
+from xml.sax.saxutils import escape
import urllib
from models import Event
import re
@@ -31,14 +32,17 @@ def post(self, type):
# order to take advantage of offline (store and forward)
# messaging.
+ message = escape(message)
+ message = message.replace("\n", "<br/>")
+
message = """
<body></body>
<html xmlns="http://jabber.org/protocol/xhtml-im">
<body xmlns="http://www.w3.org/1999/xhtml">
<p>%s</p>
</body>
</html>
-""" % message.replace("\n", "<br/>")
+""" % message
xmpp.send_message(jids=endpoint, body=message, raw_xml=True)
elif type == "web":

0 comments on commit c681dba

Please sign in to comment.