44 lines
1.6 KiB
Diff
44 lines
1.6 KiB
Diff
From f50df5120f3584c3375f1a42e413826fe9411a53 Mon Sep 17 00:00:00 2001
|
|
From: Kim Davies <kim.davies@iana.org>
|
|
Date: Sun, 3 Oct 2021 07:45:11 -0700
|
|
Subject: [PATCH] Raise IDNAError on non-ASCII A-Label (fixes #108)
|
|
|
|
Reference:https://github.com/kjd/idna/commit/f50df5120f3584c3375f1a42e413826fe9411a53
|
|
Conflict:NA
|
|
|
|
---
|
|
idna/core.py | 7 +++++--
|
|
tests/test_idna.py | 1 +
|
|
2 files changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/idna/core.py b/idna/core.py
|
|
index d605129..871ebd3 100644
|
|
--- a/idna/core.py
|
|
+++ b/idna/core.py
|
|
@@ -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
|
|
diff --git a/tests/test_idna.py b/tests/test_idna.py
|
|
index 9e1d2d9..7ac6057 100755
|
|
--- a/tests/test_idna.py
|
|
+++ b/tests/test_idna.py
|
|
@@ -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()
|