parent
b62e9e1db3
commit
3d2cedeec8
2 changed files with 20 additions and 9 deletions
|
|
@ -431,7 +431,7 @@ class Renderer(object):
|
|||
"""
|
||||
Replace line feed and/or tabs within text:span entities.
|
||||
"""
|
||||
find_pattern = r'(?is)<text:([\S]+?)>([^>]*?([\n|\t])[^<]*?)</text:\1>'
|
||||
find_pattern = r'(?is)<text:([\S]+?).*?>([^>]*?([\n\t])[^<]*?)</text:\1>'
|
||||
for m in re.findall(find_pattern, xml_text):
|
||||
replacement = m[1].replace('\n', '<text:line-break/>')
|
||||
replacement = replacement.replace('\t', '<text:tab/>')
|
||||
|
|
|
|||
|
|
@ -79,12 +79,23 @@ class RenderTestCase(TestCase):
|
|||
def test_create_text_span_node(self):
|
||||
assert self.engine.create_text_span_node(self.document, 'text').toxml() == '<text:span>text</text:span>'
|
||||
|
||||
def test_newline(self):
|
||||
xml_text = '<text:span text:style-name="T5">Teststraße 5\n1234 Lünen</text:span>'
|
||||
result = Renderer._encode_escape_chars(xml_text)
|
||||
assert result == '<text:span text:style-name="T5">Teststraße 5<text:line-break/>1234 Lünen</text:span>'
|
||||
|
||||
def test_evil_newline(self):
|
||||
xml_text = '<text:span>\n</text:span><do_not_touch>\n</do_not_touch>'
|
||||
result = Renderer._encode_escape_chars(xml_text)
|
||||
assert result == '<text:span><text:line-break/></text:span><do_not_touch>\n</do_not_touch>'
|
||||
class EncodeLFAndFWithinTextNamespace(TestCase):
|
||||
"""Test encoding of line feed and tab chars within text: namespace"""
|
||||
def test_encode_linefeed_char(self):
|
||||
xml = '<text:span>This\nLF</text:span>'
|
||||
espected = '<text:span>This<text:line-break/>LF</text:span>'
|
||||
assert (Renderer._encode_escape_chars(xml) == espected)
|
||||
|
||||
def test_encode_tab_char(self):
|
||||
xml = '<text:span>This\tTab</text:span>'
|
||||
espected = '<text:span>This<text:tab/>Tab</text:span>'
|
||||
assert (Renderer._encode_escape_chars(xml) == espected)
|
||||
|
||||
def test_escape_elem_with_attributes(self):
|
||||
"""A bug in _encode_escape_chars was preventing it from escaping
|
||||
LF and tabs inside text elements with tag attributes. See:
|
||||
https://github.com/christopher-ramirez/secretary/issues/39"""
|
||||
xml = '<text:span attr="value">This\nLF</text:span>'
|
||||
espected = '<text:span attr="value">This<text:line-break/>LF</text:span>'
|
||||
assert (Renderer._encode_escape_chars(xml) == espected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue