diff --git a/Lib/HTMLParser.py b/Lib/HTMLParser.py
index 6cc9ff13bf4..f230c5f163f 100644
--- a/Lib/HTMLParser.py
+++ b/Lib/HTMLParser.py
@@ -229,12 +229,13 @@ class HTMLParser(markupbase.ParserBase):
if rawdata[i:i+2] != '
- gtpos = rawdata.find('>', 9)
+ gtpos = rawdata.find('>', i+9)
if gtpos == -1:
return -1
self.handle_decl(rawdata[i+2:gtpos])
@@ -427,7 +428,7 @@ class HTMLParser(markupbase.ParserBase):
pass
def unknown_decl(self, data):
- self.error("unknown declaration: %r" % (data,))
+ pass
# Internal -- helper to remove special character quoting
entitydefs = None
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
index c15bb660e2b..66675127850 100644
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -215,6 +215,30 @@ text
self._parse_error("" % dtd,
+ [('decl', 'DOCTYPE ' + dtd)])
+
def test_declaration_junk_chars(self):
self._run_check("", [('decl', 'DOCTYPE foo $ ')])