Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b8147452
Commit
b8147452
authored
Nov 07, 2013
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19480: HTMLParser now accepts all valid start-tag names as defined by the HTML5 standard.
parent
a6912197
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
+17
-7
Lib/HTMLParser.py
Lib/HTMLParser.py
+7
-4
Lib/test/test_htmlparser.py
Lib/test/test_htmlparser.py
+6
-2
Misc/NEWS
Misc/NEWS
+4
-1
No files found.
Lib/HTMLParser.py
View file @
b8147452
...
...
@@ -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/]* # op
tional 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
...
...
Lib/test/test_htmlparser.py
View file @
b8147452
...
...
@@ -206,8 +206,7 @@ text
self
.
_run_check
(
"</$>"
,
[(
'comment'
,
'$'
)])
self
.
_run_check
(
"</"
,
[(
'data'
,
'</'
)])
self
.
_run_check
(
"</a"
,
[(
'data'
,
'</a'
)])
# XXX this might be wrong
self
.
_run_check
(
"<a<a>"
,
[(
'data'
,
'<a'
),
(
'starttag'
,
'a'
,
[])])
self
.
_run_check
(
"<a<a>"
,
[(
'starttag'
,
'a<a'
,
[])])
self
.
_run_check
(
"</a<a>"
,
[(
'endtag'
,
'a<a'
)])
self
.
_run_check
(
"<!"
,
[(
'data'
,
'<!'
)])
self
.
_run_check
(
"<a"
,
[(
'data'
,
'<a'
)])
...
...
@@ -215,6 +214,11 @@ text
self
.
_run_check
(
"<a foo='bar"
,
[(
'data'
,
"<a foo='bar"
)])
self
.
_run_check
(
"<a foo='>'"
,
[(
'data'
,
"<a foo='>'"
)])
self
.
_run_check
(
"<a foo='>"
,
[(
'data'
,
"<a foo='>"
)])
self
.
_run_check
(
"<a$>"
,
[(
'starttag'
,
'a$'
,
[])])
self
.
_run_check
(
"<a$b>"
,
[(
'starttag'
,
'a$b'
,
[])])
self
.
_run_check
(
"<a$b/>"
,
[(
'startendtag'
,
'a$b'
,
[])])
self
.
_run_check
(
"<a$b >"
,
[(
'starttag'
,
'a$b'
,
[])])
self
.
_run_check
(
"<a$b />"
,
[(
'startendtag'
,
'a$b'
,
[])])
def
test_valid_doctypes
(
self
):
# from http://www.w3.org/QA/2002/04/valid-dtd-list.html
...
...
Misc/NEWS
View file @
b8147452
...
...
@@ -12,8 +12,11 @@ Core and Builtins
Library
-------
- Issue #19480: HTMLParser now accepts all valid start-tag names as defined
by the HTML5 standard.
- Issue #17827: Add the missing documentation for ``codecs.encode`` and
``codecs.decode``.
``codecs.decode``.
- Issue #6157: Fixed Tkinter.Text.debug(). Original patch by Guilherme Polo.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment