]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
binascii_a2b_base64: Properly return an empty string if the input was all
authorThomas Wouters <thomas@python.org>
Mon, 17 Mar 2003 11:34:43 +0000 (11:34 +0000)
committerThomas Wouters <thomas@python.org>
Mon, 17 Mar 2003 11:34:43 +0000 (11:34 +0000)
    invalid, rather than returning a string of random garbage of the
    estimated result length. Closes SF patch #703471 by Hye-Shik Chang.

Backport from 2.3.

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

index c14f894c0d50ee579f974db1f9e0eb75f5a435cb..fc8336a3f62c51448d584eb84e6a47f275b3765d 100755 (executable)
@@ -69,6 +69,10 @@ for line in map(addnoise, lines):
     res = res + b
 verify(res == testdata)
 
+# Test base64 with just invalid characters, which should return
+# empty strings.
+verify(binascii.a2b_base64(fillers) == '')
+
 # Test uu
 print "uu test"
 MAX_UU = 45
index 2b90789c7eb38161611ba0899dd4ed478da41772..6a508a181b8a5e9d2d2970cda11b0828c2ca7076 100644 (file)
@@ -411,6 +411,10 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
        /* and set string size correctly */
        if (bin_len > 0)
                _PyString_Resize(&rv, bin_len);
+       else {
+               Py_DECREF(rv);
+               return PyString_FromString("");
+       }
        return rv;
 }