summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-04-19 01:36:03 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-04-19 01:36:03 (GMT)
commitdea6c21a9c78624786cbca0f2a318208bdc4213e (patch)
tree9c5a05cc9e9f6c63159e049566c638c4638dbb85 /Lib
parentb0b224233e481d979430a54d257d871424ff19fb (diff)
parent0780b6bc58c107a8462760163403642e889ef735 (diff)
downloadcpython-dea6c21a9c78624786cbca0f2a318208bdc4213e.zip
cpython-dea6c21a9c78624786cbca0f2a318208bdc4213e.tar.gz
cpython-dea6c21a9c78624786cbca0f2a318208bdc4213e.tar.bz2
#14538: merge with 3.2.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/html/parser.py6
-rw-r--r--Lib/test/test_htmlparser.py10
2 files changed, 13 insertions, 3 deletions
diff --git a/Lib/html/parser.py b/Lib/html/parser.py
index 2bfd187..de504ab 100644
--- a/Lib/html/parser.py
+++ b/Lib/html/parser.py
@@ -22,7 +22,7 @@ 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]*')
@@ -36,7 +36,7 @@ attrfind = re.compile(
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 @@ 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:
if self.strict:
m = attrfind.match(rawdata, k)
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
index 3e2a590..c4f80cc 100644
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -409,6 +409,16 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
('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 $ ')])