diff --git a/adsrefpipe/refparsers/unicode.py b/adsrefpipe/refparsers/unicode.py index d5ca792..39453d2 100755 --- a/adsrefpipe/refparsers/unicode.py +++ b/adsrefpipe/refparsers/unicode.py @@ -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: """ diff --git a/adsrefpipe/tests/unittests/test_ref_parsers.py b/adsrefpipe/tests/unittests/test_ref_parsers.py index 539d7b8..d0a3434 100755 --- a/adsrefpipe/tests/unittests/test_ref_parsers.py +++ b/adsrefpipe/tests/unittests/test_ref_parsers.py @@ -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[0-9A-Fa-f]+);', "򙦙") 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: 򙦙") + result = handler._UnicodeHandler__sub_hexnumasc_entity(match) + self.assertEqual(result, "") def test_sub_hexnum_toent(self): """ test __sub_hexnum_toent method """