8000 Fix to htmlentityreplace_errors when a character has no named entity.… · awesome-python/html5lib-python@fc63d15 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc63d15

Browse files
committed
Fix to htmlentityreplace_errors when a character has no named entity. Also now takes into account the fact that entity names could end with a semicolon.
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40867
1 parent 6867d5e commit fc63d15

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/html5lib/serializer/htmlserializer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ def htmlentityreplace_errors(exc):
3333
if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)):
3434
res = []
3535
for c in exc.object[exc.start:exc.end]:
36-
c = encode_entity_map.get(c)
37-
if c:
36+
e = encode_entity_map.get(c)
37+
if e:
3838
res.append("&")
39-
res.append(c)
40-
res.append(";")
39+
res.append(e)
40+
if not e.endswith(";"):
41+
res.append(";")
4142
else:
4243
res.append(c.encode(exc.encoding, "xmlcharrefreplace"))
4344
return (u"".join(res), exc.end)

0 commit comments

Comments
 (0)
0