summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-10-28 10:21:09 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-10-28 10:21:09 (GMT)
commitf50ffa94abe67c6ef5e615198af15f72e7cd2a9b (patch)
treed37cac5185ec2d8de23e854ff6dddd0bfb54cb49 /Lib
parent0b85cd06808cf9b865f91b3cf00796ab3f87914a (diff)
downloadcpython-f50ffa94abe67c6ef5e615198af15f72e7cd2a9b.zip
cpython-f50ffa94abe67c6ef5e615198af15f72e7cd2a9b.tar.gz
cpython-f50ffa94abe67c6ef5e615198af15f72e7cd2a9b.tar.bz2
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/html/parser.py5
-rw-r--r--Lib/test/test_htmlparser.py33
2 files changed, 35 insertions, 3 deletions
diff --git a/Lib/html/parser.py b/Lib/html/parser.py
index a6d5be9..affaf73 100644
--- a/Lib/html/parser.py
+++ b/Lib/html/parser.py
@@ -30,7 +30,7 @@ attrfind = re.compile(
r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?')
attrfind_tolerant = re.compile(
- r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
+ r',?\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
r'(\'[^\']*\'|"[^"]*"|[^>\s]*))?')
locatestarttagend = re.compile(r"""
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
@@ -277,12 +277,11 @@ class HTMLParser(_markupbase.ParserBase):
assert match, 'unexpected call to parse_starttag()'
k = match.end()
self.lasttag = tag = rawdata[i+1:k].lower()
-
while k < endpos:
if self.strict:
m = attrfind.match(rawdata, k)
else:
- m = attrfind_tolerant.search(rawdata, k)
+ m = attrfind_tolerant.match(rawdata, k)
if not m:
break
attrname, rest, attrvalue = m.group(1, 2, 3)
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
index d45e453..9664485 100644
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -373,6 +373,39 @@ class HTMLParserTolerantTestCase(TestCaseBase):
[('action', 'bogus|&#()value')])],
collector = self.collector)
+ def test_issue13273(self):
+ html = ('<div style="" ><b>The <a href="some_url">rain</a> '
+ '<br /> in <span>Spain</span></b></div>')
+ expected = [
+ ('starttag', 'div', [('style', '')]),
+ ('starttag', 'b', []),
+ ('data', 'The '),
+ ('starttag', 'a', [('href', 'some_url')]),
+ ('data', 'rain'),
+ ('endtag', 'a'),
+ ('data', ' '),
+ ('startendtag', 'br', []),
+ ('data', ' in '),
+ ('starttag', 'span', []),
+ ('data', 'Spain'),
+ ('endtag', 'span'),
+ ('endtag', 'b'),
+ ('endtag', 'div')
+ ]
+ self._run_check(html, expected, collector=self.collector)
+
+ def test_issue13273_2(self):
+ html = '<div style="", foo = "bar" ><b>The <a href="some_url">rain</a>'
+ expected = [
+ ('starttag', 'div', [('style', ''), ('foo', 'bar')]),
+ ('starttag', 'b', []),
+ ('data', 'The '),
+ ('starttag', 'a', [('href', 'some_url')]),
+ ('data', 'rain'),
+ ('endtag', 'a'),
+ ]
+ self._run_check(html, expected, collector=self.collector)
+
def test_unescape_function(self):
p = html.parser.HTMLParser()
self.assertEqual(p.unescape('&#bad;'),'&#bad;')