From: Martin v. Löwis Date: Thu, 25 Aug 2005 11:04:04 +0000 (+0000) Subject: Make IDNA return an empty string when the input is empty. Fixes #1163178. X-Git-Tag: v2.4.2c1~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dedff272fa40738d282d71a7763ab679fc1f40d3;p=thirdparty%2FPython%2Fcpython.git Make IDNA return an empty string when the input is empty. Fixes #1163178. --- diff --git a/Lib/encodings/idna.py b/Lib/encodings/idna.py index 48142157fdf5..f8a31d88736a 100644 --- a/Lib/encodings/idna.py +++ b/Lib/encodings/idna.py @@ -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) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 78544b2110b4..96ed5b82523b 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -632,6 +632,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): diff --git a/Misc/NEWS b/Misc/NEWS index 234401ac3f70..3710ab54c112 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -68,6 +68,8 @@ Extension Modules Library ------- +- Bug #1163178: Make IDNA return an empty string when the input is empty. + - Bug #1121494: distutils.dir_utils.mkpath now accepts Unicode strings. - Bug #1178484: Return complete lines from codec stream readers