]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Support trailing dots in DNS names. Fixes #782510.
authorMartin v. Löwis <martin@v.loewis.de>
Tue, 5 Aug 2003 06:20:23 +0000 (06:20 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Tue, 5 Aug 2003 06:20:23 +0000 (06:20 +0000)
Lib/encodings/idna.py
Lib/test/test_unicode.py
Misc/NEWS

index 62aa4502f64cc185cbf984162f1eeeaf5c635253..37462dbe11549bebcdcdbff9d019a037d10f61bd 100644 (file)
@@ -150,10 +150,16 @@ class Codec(codecs.Codec):
             raise UnicodeError, "unsupported error handling "+errors
 
         result = []
-        for label in dots.split(input):
+        labels = dots.split(input)
+        if labels and len(labels[-1])==0:
+            trailing_dot = '.'
+            del labels[-1]
+        else:
+            trailing_dot = ''
+        for label in labels:
             result.append(ToASCII(label))
         # Join with U+002E
-        return ".".join(result), len(input)
+        return ".".join(result)+trailing_dot, len(input)
 
     def decode(self,input,errors='strict'):
 
@@ -168,11 +174,17 @@ class Codec(codecs.Codec):
             unicode(input, "ascii")
             labels = input.split(".")
 
+        if labels and len(labels[-1]) == 0:
+            trailing_dot = u'.'
+            del labels[-1]
+        else:
+            trailing_dot = u''
+
         result = []
         for label in labels:
             result.append(ToUnicode(label))
 
-        return u".".join(result), len(input)
+        return u".".join(result)+trailing_dot, len(input)
 
 class StreamWriter(Codec,codecs.StreamWriter):
     pass
index 8e1f0b1b54924e355501025bf736305623e0e37b..6e40b9faf31a80e6ef27aba13e9700d03dc8227d 100644 (file)
@@ -524,6 +524,10 @@ class UnicodeTest(
         # * strict decoding testing for all of the
         #   UTF8_ERROR cases in PyUnicode_DecodeUTF8
 
+    def test_codecs_idna(self):
+        # Test whether trailing dot is preserved
+        self.assertEqual(u"www.python.org.".encode("idna"), "www.python.org.")
+
     def test_codecs_errors(self):
         # Error handling (encoding)
         self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii')
index a6317f83a36f8b49e5c5446c2ea4d1cb7ac8a65c..40fd8fb2399d23611db0bdcb4e88bd456ba1472f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,15 +18,18 @@ Extension modules
 Library
 -------
 
-- Bug #781065 was fixed: test_normalization is updated to the current
+- Bug #781065: test_normalization is updated to the current
   URL of the Unicode 3.2 normalization file.
 
 IDLE
 ----
 
-- Bug #774680 was fixed: IDLE now does not fail to save the file anymore
+- Bug #774680: IDLE now does not fail to save the file anymore
   if the Tk buffer is not a Unicode string, yet eol_convention is.
 
+- Bug #782510: The idna codec would fail to support names with a
+  trailing full-stop.
+
 Build
 -----