Skip to content

Commit c1c2363

Browse files
Merge pull request #27 from Thomas-S-Allen/issue_21_encoding
Issue 21 encoding
2 parents 5dfffc9 + 03711e8 commit c1c2363

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

adsrefpipe/refparsers/unicode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def __sub_hexnumasc_entity(self, match: re.Match) -> str:
244244
elif entno < 255:
245245
return self.u2asc(chr(entno))
246246
except IndexError:
247-
raise UnicodeHandlerError('Unknown hexadecimal entity: %s' % match.group(0))
247+
logger.error(UnicodeHandlerError('Unknown hexadecimal entity: %s' % match.group(0)))
248+
return ""
248249

249250
def __sub_hexnum_toent(self, match: re.Match) -> str:
250251
"""

adsrefpipe/tests/unittests/test_ref_parsers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,11 @@ def test_sub_hexnumasc_entity(self):
304304
handler.unicode = MagicMock()
305305
handler.unicode.__getitem__.side_effect = IndexError
306306

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

316313
def test_sub_hexnum_toent(self):
317314
""" test __sub_hexnum_toent method """

0 commit comments

Comments
 (0)