Skip to content

Commit

Permalink
Merge pull request #111 from kjd/issue-108
Browse files Browse the repository at this point in the history
Raise IDNAError on non-ASCII A-Label (fixes #108)
  • Loading branch information
kjd authored Oct 3, 2021
2 parents d0116b5 + e1023cb commit 4bfc439
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions idna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,11 @@ def encode(s, strict=False, uts46=False, std3_rules=False, transitional=False):

def decode(s, strict=False, uts46=False, std3_rules=False):
# type: (Union[str, bytes, bytearray], bool, bool, bool) -> str
if isinstance(s, (bytes, bytearray)):
s = s.decode('ascii')
try:
if isinstance(s, (bytes, bytearray)):
s = s.decode('ascii')
except UnicodeDecodeError:
raise IDNAError('Invalid ASCII in A-label')
if uts46:
s = uts46_remap(s, std3_rules, False)
trailing_dot = False
Expand Down
1 change: 1 addition & 0 deletions tests/test_idna.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def test_decode(self):
self.assertRaises(idna.IDNAError, idna.decode, 'XN---------90GGLBAGAAC.AA')
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')

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

0 comments on commit 4bfc439

Please sign in to comment.