]> granicus.if.org Git - python/commitdiff
base64.decodestring('') should return '' instead of raising an
authorBarry Warsaw <barry@python.org>
Thu, 15 Aug 2002 22:14:24 +0000 (22:14 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 15 Aug 2002 22:14:24 +0000 (22:14 +0000)
exception.  The bug fix for SF #430849 wasn't quite right.  This
closes SF bug #595671.  I'll backport this to Python 2.2.

Lib/test/test_base64.py
Modules/binascii.c

index 223c38845f19ad69892dd0dbde3aa330d5177101..42e3c81d7305dc44a740748ae06364f4f75433e2 100644 (file)
@@ -44,12 +44,7 @@ class Base64TestCase(unittest.TestCase):
             "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNTY3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") ==
             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#0^&*();:<>,. []{}",
             reason = "long decodestring failed")
-        try:
-            base64.decodestring("")
-        except binascii_error:
-            pass
-        else:
-            self.fail("expected a binascii.Error on null decode request")
+        test_support.verify(base64.decodestring('') == '')
 
 def test_main():
     test_support.run_unittest(Base64TestCase)
index 0fe85fca600601415ac8af2cc3ac225140f4c7b5..c56d528ef47f28bbf20e530eb9bea4497c09d41a 100644 (file)
@@ -346,10 +346,6 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
        if ( !PyArg_ParseTuple(args, "t#:a2b_base64", &ascii_data, &ascii_len) )
                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 */
 
        /* Allocate the buffer */
@@ -413,7 +409,8 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
        }
 
        /* and set string size correctly */
-       _PyString_Resize(&rv, bin_len);
+       if (bin_len > 0)
+               _PyString_Resize(&rv, bin_len);
        return rv;
 }