christopher-ramirez / secretary

Take the power of Jinja2 templates to OpenOffice and LibreOffice.
Other
190 stars 48 forks source link

Crash while catching exception in_render_xml() #33

Closed RomainTT closed 7 years ago

RomainTT commented 7 years ago

Hi !

While I was modifying a piece of code to manage markdown tables (and so was messing with the xml document), I found a bug:

[...]/secretary.py", line 554, in _render_xml
    near = result.split('\n')[e.lineno -1][e.offset-200:e.offset+200]
UnboundLocalError: local variable 'result' referenced before assignment

Indeed, the try block catches exception from a big piece of code and the exception is probably raised before the assignment of result.

I suggest to check the existence of result before using it in the except ExpatError block.

christopher-ramirez commented 7 years ago

Thanks for reporting this. I will take a look into it.

RomainTT commented 7 years ago

Ok I found the reason: I had <> characters in my markdown raw text. These characters are not escaped and are interpreted by the XML parser (but it crashes because these are not real tags).

I think a solution would be to replace < and > in the markdown_filter function, with &lt; and &gt; Same for ampersand, quotes and double quotes (&amp;,&apos; and&quot;)