]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of fix for SF bug #595671 from Python 2.3cvs:
authorBarry Warsaw <barry@python.org>
Thu, 15 Aug 2002 22:18:11 +0000 (22:18 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 15 Aug 2002 22:18:11 +0000 (22:18 +0000)
    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.

One addition here is that there was no test of the base64 module in
Python 2.2 cvs yet, so I added that too.

Lib/test/output/test_base64 [new file with mode: 0644]
Modules/binascii.c

diff --git a/Lib/test/output/test_base64 b/Lib/test/output/test_base64
new file mode 100644 (file)
index 0000000..ec6ac2b
--- /dev/null
@@ -0,0 +1,8 @@
+test_base64
+Testing decode string ... ok
+Testing encode string ... ok
+
+----------------------------------------------------------------------
+Ran 2 tests in 0.001s
+
+OK
index 9ef305414f31b6b791c3d6fc24374fb7a1b2f38e..70d60f02488629b074110b05c972166f38f935c8 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;
 }