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 pass
return string 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=''): def get_windows_reg_env(varname, default=''):
'''asks for paths commonly used but not exposed as ENVs '''asks for paths commonly used but not exposed as ENVs
in english Windows 2003 those are: in english Windows 2003 those are:

View File

@ -608,6 +608,7 @@ class ChangeStatusMessageDialog:
beg, end = self.message_buffer.get_bounds() beg, end = self.message_buffer.get_bounds()
message = self.message_buffer.get_text(beg, end).decode('utf-8')\ message = self.message_buffer.get_text(beg, end).decode('utf-8')\
.strip() .strip()
message = helpers.remove_invalid_xml_chars(message)
msg = helpers.to_one_line(message) msg = helpers.to_one_line(message)
if self.show: if self.show:
gajim.config.set('last_status_msg_' + self.show, msg) gajim.config.set('last_status_msg_' + self.show, msg)

View File

@ -2416,6 +2416,10 @@ class Interface:
# at least one character in 3 parts (before @, after @, after .) # at least one character in 3 parts (before @, after @, after .)
self.sth_at_sth_dot_sth_re = re.compile(r'\S+@\S+\.\S*[^\s)?]') 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 re.purge() # clear the regular expression cache
def on_emoticon_sort(self, emot1, emot2): def on_emoticon_sort(self, emot1, emot2):

View File

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