Skip to content

Commit

Permalink
Merge pull request #176 from kjd/issue-174
Browse files Browse the repository at this point in the history
Restore IDNAError exception for codepoints that don't exist in Unicode (fixes #174)
  • Loading branch information
kjd committed Apr 24, 2024
2 parents 1d365e1 + b0d8f3c commit 5b78296
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions idna/core.py
Expand Up @@ -240,8 +240,12 @@ def check_label(label: Union[str, bytes, bytearray]) -> None:
if intranges_contain(cp_value, idnadata.codepoint_classes['PVALID']):
continue
elif intranges_contain(cp_value, idnadata.codepoint_classes['CONTEXTJ']):
if not valid_contextj(label, pos):
raise InvalidCodepointContext('Joiner {} not allowed at position {} in {}'.format(
try:
if not valid_contextj(label, pos):
raise InvalidCodepointContext('Joiner {} not allowed at position {} in {}'.format(
_unot(cp_value), pos+1, repr(label)))
except ValueError:
raise IDNAError('Unknown codepoint adjacent to joiner {} at position {} in {}'.format(
_unot(cp_value), pos+1, repr(label)))
elif intranges_contain(cp_value, idnadata.codepoint_classes['CONTEXTO']):
if not valid_contexto(label, pos):
Expand Down
1 change: 1 addition & 0 deletions tests/test_idna.py
Expand Up @@ -270,6 +270,7 @@ def test_decode(self, decode=None, skip_str=False):
self.assertRaises(idna.IDNAError, decode, b'xn--')
self.assertRaises(idna.IDNAError, decode, b'\x8d\xd2')
self.assertRaises(idna.IDNAError, decode, b'A.A.0.a.a.A.0.a.A.A.0.a.A.0A.2.a.A.A.0.a.A.0.A.a.A0.a.a.A.0.a.fB.A.A.a.A.A.B.A.A.a.A.A.B.A.A.a.A.A.0.a.A.a.a.A.A.0.a.A.0.A.a.A0.a.a.A.0.a.fB.A.A.a.A.A.B.0A.A.a.A.A.B.A.A.a.A.A.a.A.A.B.A.A.a.A.0.a.B.A.A.a.A.B.A.a.A.A.5.a.A.0.a.Ba.A.B.A.A.a.A.0.a.Xn--B.A.A.A.a')
self.assertRaises(idna.IDNAError, decode, b'xn--ukba655qaaaa14431eeaaba.c')

if __name__ == '__main__':
unittest.main()

0 comments on commit 5b78296

Please sign in to comment.