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
164540fe
Commit
164540fe
authored
Dec 28, 2010
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Issue10759 - html.parser.unescape() fails on HTML entities with incorrect syntax
parent
3b4499c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
Lib/html/parser.py
Lib/html/parser.py
+10
-7
Lib/test/test_htmlparser.py
Lib/test/test_htmlparser.py
+5
-0
No files found.
Lib/html/parser.py
View file @
164540fe
...
...
@@ -434,13 +434,16 @@ class HTMLParser(_markupbase.ParserBase):
return
s
def
replaceEntities
(
s
):
s
=
s
.
groups
()[
0
]
if
s
[
0
]
==
"#"
:
s
=
s
[
1
:]
if
s
[
0
]
in
[
'x'
,
'X'
]:
c
=
int
(
s
[
1
:],
16
)
else
:
c
=
int
(
s
)
return
chr
(
c
)
try
:
if
s
[
0
]
==
"#"
:
s
=
s
[
1
:]
if
s
[
0
]
in
[
'x'
,
'X'
]:
c
=
int
(
s
[
1
:],
16
)
else
:
c
=
int
(
s
)
return
chr
(
c
)
except
ValueError
:
return
'&#'
+
s
+
';'
else
:
# Cannot use name2codepoint directly, because HTMLParser
# supports apos, which is not part of HTML 4
...
...
Lib/test/test_htmlparser.py
View file @
164540fe
...
...
@@ -356,6 +356,11 @@ class HTMLParserTolerantTestCase(TestCaseBase):
[(
'action'
,
'bogus|&#()value'
)])],
collector
=
self
.
collector
)
def
test_unescape_function
(
self
):
p
=
html
.
parser
.
HTMLParser
()
self
.
assertEqual
(
p
.
unescape
(
'&#bad;'
),
'&#bad;'
)
self
.
assertEqual
(
p
.
unescape
(
'&'
),
'&'
)
def
test_main
():
support
.
run_unittest
(
HTMLParserTestCase
,
HTMLParserTolerantTestCase
)
...
...
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