Skip to content

Commit

Permalink
Merge pull request #112 from kjd/issue-109
Browse files Browse the repository at this point in the history
Raise IDNAError exception on invalid A-label (fixes #109)
  • Loading branch information
kjd authored Oct 3, 2021
2 parents c3383c9 + 4fdcc18 commit b91e138
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion idna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ def ulabel(label):
check_label(label_bytes)
return label_bytes.decode('ascii')

label = label_bytes.decode('punycode')
try:
label = label_bytes.decode('punycode')
except UnicodeError:
raise IDNAError('Invalid A-label')
check_label(label)
return label

Expand Down
1 change: 1 addition & 0 deletions tests/test_idna.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def test_decode(self):
self.assertRaises(idna.IDNAError, idna.decode, 'xn---------90gglbagaac.aa')
self.assertRaises(idna.IDNAError, idna.decode, 'xn--')
self.assertRaises(idna.IDNAError, idna.decode, b'\x8d\xd2')
self.assertRaises(idna.IDNAError, idna.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')

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

0 comments on commit b91e138

Please sign in to comment.