Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adsrefpipe/refparsers/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ def __sub_hexnumasc_entity(self, match: re.Match) -> str:
elif entno < 255:
return self.u2asc(chr(entno))
except IndexError:
raise UnicodeHandlerError('Unknown hexadecimal entity: %s' % match.group(0))
logger.error(UnicodeHandlerError('Unknown hexadecimal entity: %s' % match.group(0)))
return ""

def __sub_hexnum_toent(self, match: re.Match) -> str:
"""
Expand Down
9 changes: 3 additions & 6 deletions adsrefpipe/tests/unittests/test_ref_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,11 @@ def test_sub_hexnumasc_entity(self):
handler.unicode = MagicMock()
handler.unicode.__getitem__.side_effect = IndexError

# large invalid hex value to trigger the IndexError exception
# large invalid hex value to trigger returning and empty string ""
match = re.match(r'&#x(?P<hexnum>[0-9A-Fa-f]+);', "&#x99999;")
if match:
# check that the correct exception is raised
with self.assertRaises(UnicodeHandlerError) as context:
handler._UnicodeHandler__sub_hexnumasc_entity(match)
# ensure the exception message is correct
self.assertEqual(str(context.exception), "Unknown hexadecimal entity: &#x99999;")
result = handler._UnicodeHandler__sub_hexnumasc_entity(match)
self.assertEqual(result, "")

def test_sub_hexnum_toent(self):
""" test __sub_hexnum_toent method """
Expand Down