Commit 0a51b58e authored by Barry Warsaw's avatar Barry Warsaw

base64.decodestring('') should return '' instead of raising an

exception.  The bug fix for SF #430849 wasn't quite right.  This
closes SF bug #595671.  I'll backport this to Python 2.2.
parent 7ca993ed
...@@ -44,12 +44,7 @@ class Base64TestCase(unittest.TestCase): ...@@ -44,12 +44,7 @@ class Base64TestCase(unittest.TestCase):
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") == "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") ==
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}",
reason = "long decodestring failed") reason = "long decodestring failed")
try: test_support.verify(base64.decodestring('') == '')
base64.decodestring("")
except binascii_error:
pass
else:
self.fail("expected a binascii.Error on null decode request")
def test_main(): def test_main():
test_support.run_unittest(Base64TestCase) test_support.run_unittest(Base64TestCase)
......
...@@ -346,10 +346,6 @@ binascii_a2b_base64(PyObject *self, PyObject *args) ...@@ -346,10 +346,6 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
if ( !PyArg_ParseTuple(args, "t#:a2b_base64", &ascii_data, &ascii_len) ) if ( !PyArg_ParseTuple(args, "t#:a2b_base64", &ascii_data, &ascii_len) )
return NULL; return NULL;
if ( ascii_len == 0) {
PyErr_SetString(Error, "Cannot decode empty input");
return NULL;
}
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */ bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
/* Allocate the buffer */ /* Allocate the buffer */
...@@ -413,7 +409,8 @@ binascii_a2b_base64(PyObject *self, PyObject *args) ...@@ -413,7 +409,8 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
} }
/* and set string size correctly */ /* and set string size correctly */
_PyString_Resize(&rv, bin_len); if (bin_len > 0)
_PyString_Resize(&rv, bin_len);
return rv; return rv;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment