mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Make IDNA return an empty string when the input is empty. Fixes #1163178.
Will backport to 2.4.
This commit is contained in:
parent
8246c439a8
commit
8b59514e57
3 changed files with 14 additions and 0 deletions
|
@ -149,6 +149,9 @@ class Codec(codecs.Codec):
|
||||||
# IDNA is quite clear that implementations must be strict
|
# IDNA is quite clear that implementations must be strict
|
||||||
raise UnicodeError, "unsupported error handling "+errors
|
raise UnicodeError, "unsupported error handling "+errors
|
||||||
|
|
||||||
|
if not input:
|
||||||
|
return "", 0
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
labels = dots.split(input)
|
labels = dots.split(input)
|
||||||
if labels and len(labels[-1])==0:
|
if labels and len(labels[-1])==0:
|
||||||
|
@ -166,6 +169,9 @@ class Codec(codecs.Codec):
|
||||||
if errors != 'strict':
|
if errors != 'strict':
|
||||||
raise UnicodeError, "Unsupported error handling "+errors
|
raise UnicodeError, "Unsupported error handling "+errors
|
||||||
|
|
||||||
|
if not input:
|
||||||
|
return u"", 0
|
||||||
|
|
||||||
# IDNA allows decoding to operate on Unicode strings, too.
|
# IDNA allows decoding to operate on Unicode strings, too.
|
||||||
if isinstance(input, unicode):
|
if isinstance(input, unicode):
|
||||||
labels = dots.split(input)
|
labels = dots.split(input)
|
||||||
|
|
|
@ -630,6 +630,12 @@ class CodecTest(unittest.TestCase):
|
||||||
def test_builtin(self):
|
def test_builtin(self):
|
||||||
self.assertEquals(unicode("python.org", "idna"), u"python.org")
|
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):
|
class CodecsModuleTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_decode(self):
|
def test_decode(self):
|
||||||
|
|
|
@ -193,6 +193,8 @@ Extension Modules
|
||||||
Library
|
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
|
- Patch #848017: Make Cookie more RFC-compliant. Use CRLF as default output
|
||||||
separator and do not output trailing semicola.
|
separator and do not output trailing semicola.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue