(original) (raw)

changeset: 76414:ba4baaddac8d branch: 3.2 parent: 76409:292cbd59dbe0 user: Ezio Melotti ezio.melotti@gmail.com date: Wed Apr 18 19🔞22 2012 -0600 files: Lib/html/parser.py Lib/test/test_htmlparser.py Misc/NEWS description: #14538: HTMLParser can now parse correctly start tags that contain a bare /. diff -r 292cbd59dbe0 -r ba4baaddac8d Lib/html/parser.py --- a/Lib/html/parser.py Wed Apr 18 12:48:52 2012 -0700 +++ b/Lib/html/parser.py Wed Apr 18 19🔞22 2012 -0600 @@ -22,7 +22,7 @@ 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]*') @@ -36,7 +36,7 @@ r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*' r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?') attrfind_tolerant = re.compile( - r'[\s/]*((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*' + r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*' r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*') locatestarttagend = re.compile(r""" <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name @@ -327,7 +327,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: if self.strict: m = attrfind.match(rawdata, k) diff -r 292cbd59dbe0 -r ba4baaddac8d Lib/test/test_htmlparser.py --- a/Lib/test/test_htmlparser.py Wed Apr 18 12:48:52 2012 -0700 +++ b/Lib/test/test_htmlparser.py Wed Apr 18 19🔞22 2012 -0600 @@ -409,6 +409,16 @@ ('starttag', 'a', [('foo', None), ('=', None), ('bar', None)]) ] self._run_check(html, expected) + #see issue #14538 + html = ('' + '') + expected = [ + ('starttag', 'meta', []), ('starttag', 'meta', []), + ('starttag', 'meta', []), ('starttag', 'meta', []), + ('startendtag', 'meta', []), ('startendtag', 'meta', []), + ('startendtag', 'meta', []), ('startendtag', 'meta', []), + ] + self._run_check(html, expected) def test_declaration_junk_chars(self): self._run_check("", [('decl', 'DOCTYPE foo $ ')]) diff -r 292cbd59dbe0 -r ba4baaddac8d Misc/NEWS --- a/Misc/NEWS Wed Apr 18 12:48:52 2012 -0700 +++ b/Misc/NEWS Wed Apr 18 19🔞22 2012 -0600 @@ -47,6 +47,9 @@ Library ------- +- Issue #14538: HTMLParser can now parse correctly start tags that contain + a bare '/'. + - Issue #14452: SysLogHandler no longer inserts a UTF-8 BOM into the message. - Issue #13496: Fix potential overflow in bisect.bisect algorithm when applied /ezio.melotti@gmail.com