Mercurial > cpython-lru_cache-weakref
diff Lib/HTMLParser.py @ 76413:36c901fcfcda 2.7
#14538: HTMLParser can now parse correctly start tags that contain a bare /.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Wed, 18 Apr 2012 19:08:41 -0600 |
| parents | 37c824c3efe8 |
| children | 695f988824bb |
line wrap: on
line diff
--- a/Lib/HTMLParser.py Wed Apr 18 16:41:56 2012 -0700 +++ b/Lib/HTMLParser.py Wed Apr 18 19:08:41 2012 -0600 @@ -22,13 +22,13 @@ 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 # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*') attrfind = re.compile( - r'[\s/]*((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*' + r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*' r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*') locatestarttagend = re.compile(r""" @@ -289,7 +289,7 @@ match = tagfind.match(rawdata, i+1) assert match, 'unexpected call to parse_starttag()' k = match.end() - self.lasttag = tag = rawdata[i+1:k].lower() + self.lasttag = tag = match.group(1).lower() while k < endpos: m = attrfind.match(rawdata, k)
