]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#14538: HTMLParser can now parse correctly start tags that contain a bare /.
authorEzio Melotti <ezio.melotti@gmail.com>
Thu, 19 Apr 2012 01:08:41 +0000 (19:08 -0600)
committerEzio Melotti <ezio.melotti@gmail.com>
Thu, 19 Apr 2012 01:08:41 +0000 (19:08 -0600)
Lib/HTMLParser.py
Lib/test/test_htmlparser.py
Misc/NEWS

index d4e14d438769bd71469c63838c0098865234f509..b336a4c31df64988f41f094cd9cb3912ff939d59 100644 (file)
@@ -22,13 +22,13 @@ charref = re.compile('&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]')
 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 @@ 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()
+        self.lasttag = tag = match.group(1).lower()
 
         while k < endpos:
             m = attrfind.match(rawdata, k)
index 41f43408d83525f3bfd6f0a35f9f30980e7b0bdb..8cc461f1ee3404a5c1bc11c75ef52ff3ac98b877 100644 (file)
@@ -260,6 +260,16 @@ text
             ('starttag', 'a', [('foo', None), ('=', None), ('bar', None)])
         ]
         self._run_check(html, expected)
+        #see issue #14538
+        html = ('<meta><meta / ><meta // ><meta / / >'
+                '<meta/><meta /><meta //><meta//>')
+        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("<!DOCTYPE foo $ >", [('decl', 'DOCTYPE foo $ ')])
index 6b278bd8b7dd48f9850c80e3e36790e1577ddd04..6ae6e53e3a79b74b5702f05cd94b8660e0833080 100644 (file)
--- 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
+  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