summaryrefslogtreecommitdiffstats
path: root/Lib/HTMLParser.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-11-07 16:31:36 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-11-07 16:31:36 (GMT)
commitb8147452265077d4c12464a9943903f0d040f79c (patch)
treefa6d0969cabf2cb14c99e7f049978d3b9f675527 /Lib/HTMLParser.py
parenta691219716ea8f2089fb35c573a1f055872d4da2 (diff)
downloadcpython-b8147452265077d4c12464a9943903f0d040f79c.zip
cpython-b8147452265077d4c12464a9943903f0d040f79c.tar.gz
cpython-b8147452265077d4c12464a9943903f0d040f79c.tar.bz2
#19480: HTMLParser now accepts all valid start-tag names as defined by the HTML5 standard.
Diffstat (limited to 'Lib/HTMLParser.py')
-rw-r--r--Lib/HTMLParser.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/HTMLParser.py b/Lib/HTMLParser.py
index b336a4c..5a55e26 100644
--- a/Lib/HTMLParser.py
+++ b/Lib/HTMLParser.py
@@ -22,9 +22,12 @@ 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:_]*)(?:\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
+# note: if you change tagfind/attrfind remember to update locatestarttagend too
+tagfind = re.compile('([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
+# this regex is currently unused, but left for backward compatibility
tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*')
attrfind = re.compile(
@@ -32,7 +35,7 @@ attrfind = re.compile(
r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*')
locatestarttagend = re.compile(r"""
- <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
+ <[a-zA-Z][^\t\n\r\f />\x00]* # tag name
(?:[\s/]* # optional whitespace before attribute name
(?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name
(?:\s*=+\s* # value indicator
@@ -373,14 +376,14 @@ class HTMLParser(markupbase.ParserBase):
self.handle_data(rawdata[i:gtpos])
return gtpos
# find the name: w3.org/TR/html5/tokenization.html#tag-name-state
- namematch = tagfind_tolerant.match(rawdata, i+2)
+ namematch = tagfind.match(rawdata, i+2)
if not namematch:
# w3.org/TR/html5/tokenization.html#end-tag-open-state
if rawdata[i:i+3] == '</>':
return i+3
else:
return self.parse_bogus_comment(i)
- tagname = namematch.group().lower()
+ tagname = namematch.group(1).lower()
# consume and ignore other stuff between the name and the >
# Note: this is not 100% correct, since we might have things like
# </tag attr=">">, but looking for > after tha name should cover