malthe / chameleon

Fast HTML/XML template engine for Python
https://chameleon.readthedocs.io
Other
177 stars 64 forks source link

Some syntax errors are badly handled #298

Open d-maurer opened 5 years ago

d-maurer commented 5 years ago

This is a reformulation of https://github.com/zopefoundation/Zope/issues/710.

When the template

<html><body>
<div \
   >
   div with syntax error in start tag
   <div>nested div</div>
</div>
</body></html>

is parsed with content type text/html, the parser correctly recognizes the malformed div start tag and calls visit on chameleon.parser.ElementParser with kind error. This looks for visit_error and because this is undefined uses vist_default instead -- which turns the bad start tag into a text node. As a consequence, the start/end tag structure is broken and an error is reported (potentially much) later regarding a mismatch end tag.

ElementParser should define visit_error and ensure that the error is reported immediately.

dataflake commented 4 years ago

@malthe Shouldn't this be marked as a bug and not a feature?

malthe commented 4 years ago

I suppose in this case it's a bit of a grey area :-)

d-maurer commented 4 years ago

Malthe Borch wrote at 2020-7-15 12:47 -0700:

I suppose in this case it's a bit of a grey area :-)

I have spent hours to understand what happened in a concrete (complex) case: in this case, I got a parser error "mismatched closing tag" far below the buggy open tag (and not refering to it).

Just ignoring an open tag containing some type of bugs is not helpful for locating the problem.