diff --git a/Lib/html/parser.py b/Lib/html/parser.py index 1b8b6ea0e5ab7a..1e30956fe24f83 100644 --- a/Lib/html/parser.py +++ b/Lib/html/parser.py @@ -260,7 +260,7 @@ def goahead(self, end): else: assert 0, "interesting.search() lied" # end while - if end and i < n and not self.cdata_elem: + if end and i < n: if self.convert_charrefs and not self.cdata_elem: self.handle_data(unescape(rawdata[i:n])) else: diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py index 68649e9d6d5e9c..61fa24fab574f2 100644 --- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -317,6 +317,16 @@ def get_events(self): ("endtag", element_lower)], collector=Collector(convert_charrefs=False)) + def test_EOF_in_cdata(self): + content = """ ¬-an-entity-ref; +
+ ''""" + s = f'