diff options
author | Bob Halley <halley@dnspython.org> | 2020-07-23 06:33:27 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2020-07-23 06:33:27 -0700 |
commit | 16417623fb9221a978e67b62865a65acdb716d20 (patch) | |
tree | b1406d23c229ef8d517f4fcf8091d26014a86b37 | |
parent | fd24f0d3d53e1aff7d63cd5cc5e93c35f807678e (diff) | |
download | dnspython-16417623fb9221a978e67b62865a65acdb716d20.tar.gz |
Improve name coverage slightly by testing the uts_46 branch in 2008 decode.
I'm not sure how useful in practice this is, as we don't offer a codec
configuration default for it, but I'm not sure you'd never do it, and the
existing code was in the wrong order.
-rw-r--r-- | dns/name.py | 5 | ||||
-rw-r--r-- | tests/test_name.py | 30 |
2 files changed, 27 insertions, 8 deletions
diff --git a/dns/name.py b/dns/name.py index 529ae7f..94d7b93 100644 --- a/dns/name.py +++ b/dns/name.py @@ -215,9 +215,10 @@ class IDNA2008Codec(IDNACodec): if not have_idna_2008: raise NoIDNA2008 try: + ulabel = idna.ulabel(label) if self.uts_46: - label = idna.uts46_remap(label, False, False) - return _escapify(idna.ulabel(label)) + ulabel = idna.uts46_remap(ulabel, False, self.transitional) + return _escapify(ulabel) except (idna.IDNAError, UnicodeError) as e: raise IDNAException(idna_exception=e) diff --git a/tests/test_name.py b/tests/test_name.py index dec8c5f..0d3f968 100644 --- a/tests/test_name.py +++ b/tests/test_name.py @@ -781,12 +781,30 @@ class NameTestCase(unittest.TestCase): @unittest.skipUnless(dns.name.have_idna_2008, 'Python idna cannot be imported; no IDNA2008') def testToUnicode4(self): - if dns.name.have_idna_2008: - n = dns.name.from_text('ドメイン.テスト', - idna_codec=dns.name.IDNA_2008) - s = n.to_unicode() - self.assertEqual(str(n), 'xn--eckwd4c7c.xn--zckzah.') - self.assertEqual(s, 'ドメイン.テスト.') + n = dns.name.from_text('ドメイン.テスト', + idna_codec=dns.name.IDNA_2008) + s = n.to_unicode() + self.assertEqual(str(n), 'xn--eckwd4c7c.xn--zckzah.') + self.assertEqual(s, 'ドメイン.テスト.') + + @unittest.skipUnless(dns.name.have_idna_2008, + 'Python idna cannot be imported; no IDNA2008') + def testToUnicode5(self): + # Exercise UTS 46 remapping in decode. This doesn't normally happen + # as you can see from us having to instantiate the codec as + # transitional with strict decoding, not one of our usual choices. + codec = dns.name.IDNA2008Codec(True, True, False, True) + n = dns.name.from_text('xn--gro-7ka.com') + self.assertEqual(n.to_unicode(idna_codec=codec), + 'gross.com.') + + @unittest.skipUnless(dns.name.have_idna_2008, + 'Python idna cannot be imported; no IDNA2008') + def testToUnicode6(self): + # Test strict 2008 decoding without UTS 46 + n = dns.name.from_text('xn--gro-7ka.com') + self.assertEqual(n.to_unicode(idna_codec=dns.name.IDNA_2008_Strict), + 'groß.com.') def testDefaultDecodeIsJustPunycode(self): # groß.com. in IDNA2008 form, pre-encoded. |