Index: Lib/HTMLParser.py =================================================================== --- Lib/HTMLParser.py (revision 80555) +++ Lib/HTMLParser.py (working copy) @@ -175,6 +175,9 @@ i = self.updatepos(i, k) continue else: + if ";" in rawdata[i:]: #bail by consuming &# + self.handle_data(rawdata[0:2]) + i = self.updatepos(i, 2) break elif startswith('&', i): match = entityref.match(rawdata, i) Index: Lib/test/test_htmlparser.py =================================================================== --- Lib/test/test_htmlparser.py (revision 80555) +++ Lib/test/test_htmlparser.py (working copy) @@ -114,6 +114,7 @@ sample text “ +&#bad; """, [ @@ -129,7 +130,7 @@ ("starttag", "img", [("src", "Bar"), ("ismap", None)]), ("data", "sample\ntext\n"), ("charref", "x201C"), - ("data", "\n"), + ("data", "\n&#bad;\n"), ("comment", "comment2a-- --comment2b"), ("data", "\n"), ("endtag", "html"),