diff options
author | mathieui <mathieui@mathieui.net> | 2014-12-08 17:01:44 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-12-08 17:01:44 +0100 |
commit | e273a32ec727700d592723c4e5905510c71ed632 (patch) | |
tree | 47b04cad0ca7dfb7a79166140eca040fd8ee2870 /src/xhtml.py | |
parent | 4b8749ca88ef5a7e525231893b813eb0d4b2f8c1 (diff) | |
download | poezio-e273a32ec727700d592723c4e5905510c71ed632.tar.gz poezio-e273a32ec727700d592723c4e5905510c71ed632.tar.bz2 poezio-e273a32ec727700d592723c4e5905510c71ed632.tar.xz poezio-e273a32ec727700d592723c4e5905510c71ed632.zip |
Improve the xhtml_to_poezio_colors sanitization
add some tests, and remove the test_datetime_tuple because
of python time module misbehavior with timezones set manually.
(potentially due to http://bugs.python.org/issue6478)
Diffstat (limited to 'src/xhtml.py')
-rw-r--r-- | src/xhtml.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/xhtml.py b/src/xhtml.py index 5b71823c..b84ce943 100644 --- a/src/xhtml.py +++ b/src/xhtml.py @@ -183,7 +183,8 @@ whitespace_re = re.compile(r'\s+') xhtml_attr_re = re.compile(r'\x19-?\d[^}]*}|\x19[buaio]') xhtml_data_re = re.compile(r'data:image/([a-z]+);base64,(.+)') -poezio_colors_trim = re.compile(r'\x19o(\x19\d+}|\x19\d|\x19[buaio])*\x19o') +poezio_color_double = re.compile(r'(?:\x19\d+}|\x19\d)+(\x19\d|\x19\d+})') +poezio_format_trim = re.compile(r'(\x19\d+}|\x19\d|\x19[buaio]|\x19o)+\x19o') xhtml_simple_attr_re = re.compile(r'\x19\d') @@ -304,7 +305,8 @@ class XHTMLHandler(sax.ContentHandler): @property def result(self): - return re.sub(poezio_colors_trim, '\x19o', ''.join(self.builder).strip()) + sanitized = re.sub(poezio_color_double, r'\1', ''.join(self.builder).strip()) + return re.sub(poezio_format_trim, '\x19o', sanitized) def append_formatting(self, formatting): self.formatting.append(formatting) |