def parse_comment(self, i, report=True):
rawdata = self.rawdata
assert rawdata.startswith('<!--', i), 'unexpected call to parse_comment()'
- match = commentclose.search(rawdata, i+4)
+ # An empty comment is abruptly closed by the first ">" or "->",
+ # taking priority over a later "-->" or "--!>" close.
+ match = commentabruptclose.match(rawdata, i+4)
if not match:
- match = commentabruptclose.match(rawdata, i+4)
+ match = commentclose.search(rawdata, i+4)
if not match:
return -1
if report:
*, collector=None, convert_charrefs=False):
if collector is None:
collector = self.get_collector(convert_charrefs=convert_charrefs)
+ if isinstance(source, str):
+ # Also feed the whole string at once, not just character by
+ # character (below), to exercise different input buffering.
+ self._run_check([source], expected_events,
+ convert_charrefs=convert_charrefs)
parser = collector
for s in source:
parser.feed(s)
'<!-- <!-- nested --> -->'
'<!--<!-->'
'<!--<!--!>'
+ # abruptly closed empty comment must not swallow later text
+ '<!-->x-->'
+ '<!--->y-->'
)
expected = [('comment', " I'm a valid comment "),
('comment', 'me too!'),
('comment', ' <!-- nested '), ('data', ' -->'),
('comment', '<!'),
('comment', '<!'),
+ ('comment', ''), ('data', 'x-->'),
+ ('comment', ''), ('data', 'y-->'),
]
self._run_check(html, expected)