]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make IDNA return an empty string when the input is empty. Fixes #1163178.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 25 Aug 2005 11:03:38 +0000 (11:03 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 25 Aug 2005 11:03:38 +0000 (11:03 +0000)
Will backport to 2.4.

Lib/encodings/idna.py
Lib/test/test_codecs.py
Misc/NEWS

index 48142157fdf5a7fef8ddbaa6520e258a2e8d4675..f8a31d88736a83cd6342fb6e807793a79833f592 100644 (file)
@@ -149,6 +149,9 @@ class Codec(codecs.Codec):
             # IDNA is quite clear that implementations must be strict
             raise UnicodeError, "unsupported error handling "+errors
 
+        if not input:
+            return "", 0
+
         result = []
         labels = dots.split(input)
         if labels and len(labels[-1])==0:
@@ -166,6 +169,9 @@ class Codec(codecs.Codec):
         if errors != 'strict':
             raise UnicodeError, "Unsupported error handling "+errors
 
+        if not input:
+            return u"", 0
+
         # IDNA allows decoding to operate on Unicode strings, too.
         if isinstance(input, unicode):
             labels = dots.split(input)
index 5f799e0515404b6f082359da10c6c8d362a04864..5189e80b7398183f2d69df30f5d1a8b5573e396f 100644 (file)
@@ -630,6 +630,12 @@ class CodecTest(unittest.TestCase):
     def test_builtin(self):
         self.assertEquals(unicode("python.org", "idna"), u"python.org")
 
+    def test_stream(self):
+        import StringIO
+        r = codecs.getreader("idna")(StringIO.StringIO("abc"))
+        r.read(3)
+        self.assertEquals(r.read(), u"")
+
 class CodecsModuleTest(unittest.TestCase):
 
     def test_decode(self):
index 20e1f8938d64085e2181b3adfd4f8a62c557c93f..89efcad2133e1ea1e82780cd0d8f762657095e05 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -193,6 +193,8 @@ Extension Modules
 Library
 -------
 
+- Bug #1163178: Make IDNA return an empty string when the input is empty.
+
 - Patch #848017: Make Cookie more RFC-compliant. Use CRLF as default output
   separator and do not output trailing semicola.