prevent sending invalid XML chars in chat / groupchat and status. Fixes #3296

This commit is contained in:
Yann Leboulanger 2008-07-30 12:21:47 +00:00
parent b3dd46acae
commit d030cd8b03
4 changed files with 18 additions and 4 deletions

View File

@ -645,6 +645,11 @@ def ensure_utf8_string(string):
pass
return string
def remove_invalid_xml_chars(string):
if string:
string = re.sub(gajim.interface.invalid_XML_chars_re, '', string)
return string
def get_windows_reg_env(varname, default=''):
'''asks for paths commonly used but not exposed as ENVs
in english Windows 2003 those are:
@ -1287,4 +1292,4 @@ def update_optional_features(account = None):
gajim.connections[a].change_status(gajim.SHOW_LIST[connected],
gajim.connections[a].status)
# vim: se ts=3:
# vim: se ts=3:

View File

@ -608,6 +608,7 @@ class ChangeStatusMessageDialog:
beg, end = self.message_buffer.get_bounds()
message = self.message_buffer.get_text(beg, end).decode('utf-8')\
.strip()
message = helpers.remove_invalid_xml_chars(message)
msg = helpers.to_one_line(message)
if self.show:
gajim.config.set('last_status_msg_' + self.show, msg)
@ -3847,4 +3848,4 @@ class ESessionInfoWindow:
self.session.verified_identity = True
self.update_info()
# vim: se ts=3:
# vim: se ts=3:

View File

@ -2416,6 +2416,10 @@ class Interface:
# at least one character in 3 parts (before @, after @, after .)
self.sth_at_sth_dot_sth_re = re.compile(r'\S+@\S+\.\S*[^\s)?]')
# Invalid XML chars
invalid_XML_chars = u'[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x19]|[\ud800-\udfff]|[\ufffe-\uffff]'
self.invalid_XML_chars_re = re.compile(invalid_XML_chars)
re.purge() # clear the regular expression cache
def on_emoticon_sort(self, emot1, emot2):
@ -3291,4 +3295,4 @@ if __name__ == '__main__':
except KeyboardInterrupt:
print >> sys.stderr, 'KeyboardInterrupt'
# vim: se ts=3:
# vim: se ts=3:

View File

@ -20,6 +20,7 @@
import gtkgui_helpers
from common import gajim
from common import helpers
# Derived types MUST register their type IDs here if custom behavor is required
TYPE_CHAT = 'chat'
@ -154,6 +155,9 @@ class MessageControl:
# Send the given message to the active tab.
# Doesn't return None if error
jid = self.contact.jid
message = helpers.remove_invalid_xml_chars(message)
original_message = message
conn = gajim.connections[self.account]
@ -176,4 +180,4 @@ class MessageControl:
session = self.session,
original_message = original_message)
# vim: se ts=3:
# vim: se ts=3: