summaryrefslogtreecommitdiff
path: root/Lib/html
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-12-28 15:55:16 +0000
committerSenthil Kumaran <orsenthil@gmail.com>2010-12-28 15:55:16 +0000
commit9fb73ba7ee16a8aa4e60057e45e0065fb108c455 (patch)
tree7247087eb77277a26adc53e70d837d39a0c5adab /Lib/html
parent8e96c6aefa4d9528ee15401304f9f0be7c540dd8 (diff)
downloadcpython-9fb73ba7ee16a8aa4e60057e45e0065fb108c455.tar.gz
Fix Issue10759 - html.parser.unescape() fails on HTML entities with incorrect syntax
Diffstat (limited to 'Lib/html')
-rw-r--r--Lib/html/parser.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/html/parser.py b/Lib/html/parser.py
index 8d275ab315..21ebbc3eaf 100644
--- a/Lib/html/parser.py
+++ b/Lib/html/parser.py
@@ -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