cpython: 36c901fcfcda (original) (raw)
--- a/Lib/HTMLParser.py +++ b/Lib/HTMLParser.py @@ -22,13 +22,13 @@ charref = re.compile('&#(?:[0-9]+|[xX][0 starttagopen = re.compile('<[a-zA-Z]') piclose = re.compile('>') commentclose = re.compile(r'--\s*>') -tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:]*') +tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:])(?:\s|/(?!>))')
see http://www.w3.org/TR/html5/tokenization.html#tag-open-state[](#l1.9)
and http://www.w3.org/TR/html5/tokenization.html#tag-name-state[](#l1.10)
tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*') attrfind = re.compile(
- r'((?<=['"\s/])[^\s/>][^\s/=>])(\s=+\s*' r'('[^']'|"[^"]"|(?!['"])[^>\s]))?(?:\s|/(?!>))') locatestarttagend = re.compile(r""" @@ -289,7 +289,7 @@ class HTMLParser(markupbase.ParserBase): match = tagfind.match(rawdata, i+1) assert match, 'unexpected call to parse_starttag()' k = match.end()
self.lasttag = tag = rawdata[i+1:k].lower()[](#l1.23)
self.lasttag = tag = match.group(1).lower()[](#l1.24)
while k < endpos: m = attrfind.match(rawdata, k)
--- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -260,6 +260,16 @@ text ('starttag', 'a', [('foo', None), ('=', None), ('bar', None)]) ] self._run_check(html, expected)
#see issue #14538[](#l2.7)
html = ('<meta><meta / ><meta // ><meta / / >'[](#l2.8)
'<meta/><meta /><meta //><meta//>')[](#l2.9)
expected = [[](#l2.10)
('starttag', 'meta', []), ('starttag', 'meta', []),[](#l2.11)
('starttag', 'meta', []), ('starttag', 'meta', []),[](#l2.12)
('startendtag', 'meta', []), ('startendtag', 'meta', []),[](#l2.13)
('startendtag', 'meta', []), ('startendtag', 'meta', []),[](#l2.14)
][](#l2.15)
self._run_check(html, expected)[](#l2.16)
def test_declaration_junk_chars(self): self._run_check("", [('decl', 'DOCTYPE foo $ ')])
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -50,6 +50,9 @@ Core and Builtins Library ------- +- Issue #14538: HTMLParser can now parse correctly start tags that contain