Fix for a privately reported bug

This commit is contained in:
Miroslav Stampar
2016-10-08 21:11:43 +02:00
parent e4b0ac9ae5
commit b51b80b174
3 changed files with 25 additions and 21 deletions

View File

@@ -512,25 +512,29 @@ class Tag(PageElement):
entities with the appropriate Unicode characters. If HTML
entities are being converted, any unrecognized entities are
escaped."""
x = match.group(1)
if self.convertHTMLEntities and x in name2codepoint:
return unichr(name2codepoint[x])
elif x in self.XML_ENTITIES_TO_SPECIAL_CHARS:
if self.convertXMLEntities:
return self.XML_ENTITIES_TO_SPECIAL_CHARS[x]
else:
return u'&%s;' % x
elif len(x) > 0 and x[0] == '#':
# Handle numeric entities
if len(x) > 1 and x[1] == 'x':
return unichr(int(x[2:], 16))
else:
return unichr(int(x[1:]))
try:
x = match.group(1)
if self.convertHTMLEntities and x in name2codepoint:
return unichr(name2codepoint[x])
elif x in self.XML_ENTITIES_TO_SPECIAL_CHARS:
if self.convertXMLEntities:
return self.XML_ENTITIES_TO_SPECIAL_CHARS[x]
else:
return u'&%s;' % x
elif len(x) > 0 and x[0] == '#':
# Handle numeric entities
if len(x) > 1 and x[1] == 'x':
return unichr(int(x[2:], 16))
else:
return unichr(int(x[1:]))
elif self.escapeUnrecognizedEntities:
return u'&%s;' % x
else:
return u'&%s;' % x
elif self.escapeUnrecognizedEntities:
return u'&%s;' % x
except ValueError: # e.g. ValueError: unichr() arg not in range(0x10000)
pass
return u'&%s;' % x
def __init__(self, parser, name, attrs=None, parent=None,
previous=None):