]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #25913: Leading <~ is optional now in base64.a85decode() with adobe=True.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 24 Feb 2016 10:05:50 +0000 (12:05 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 24 Feb 2016 10:05:50 +0000 (12:05 +0200)
Patch by Swati Jaiswal.

Lib/base64.py
Lib/test/test_base64.py
Misc/NEWS

index e2c597b0ca6b83f53fc36e37285dc8e92c101f7b..adaec1de61bf423f332c8c5df714ee06ded596b3 100755 (executable)
@@ -367,10 +367,15 @@ def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
     """
     b = _bytes_from_decode_data(b)
     if adobe:
-        if not (b.startswith(_A85START) and b.endswith(_A85END)):
-            raise ValueError("Ascii85 encoded byte sequences must be bracketed "
-                             "by {!r} and {!r}".format(_A85START, _A85END))
-        b = b[2:-2] # Strip off start/end markers
+        if not b.endswith(_A85END):
+            raise ValueError(
+                "Ascii85 encoded byte sequences must end "
+                "with {!r}".format(_A85END)
+                )
+        if b.startswith(_A85START):
+            b = b[2:-2]  # Strip off start/end markers
+        else:
+            b = b[:-2]
     #
     # We have to go through this stepwise, so as to ignore spaces and handle
     # special short sequences
index 9b853a854b32c4c2b4afd287b6f062886e6a1c86..4f86aaa0c0eb49930483f4ff3ba741b48023703c 100644 (file)
@@ -494,6 +494,7 @@ class BaseXYTestCase(unittest.TestCase):
             eq(base64.a85decode(data, adobe=False), res, data)
             eq(base64.a85decode(data.decode("ascii"), adobe=False), res, data)
             eq(base64.a85decode(b'<~' + data + b'~>', adobe=True), res, data)
+            eq(base64.a85decode(data + b'~>', adobe=True), res, data)
             eq(base64.a85decode('<~%s~>' % data.decode("ascii"), adobe=True),
                res, data)
 
@@ -584,8 +585,6 @@ class BaseXYTestCase(unittest.TestCase):
                                       b"malformed", adobe=True)
         self.assertRaises(ValueError, base64.a85decode,
                                       b"<~still malformed", adobe=True)
-        self.assertRaises(ValueError, base64.a85decode,
-                                      b"also malformed~>", adobe=True)
 
         # With adobe=False (the default), Adobe framing markers are disallowed
         self.assertRaises(ValueError, base64.a85decode,
index c47ca6082579289ada7cd69b074de4897c6a7359..fd4ca59277ca884569b8aa27b5042f867ae70579 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -76,6 +76,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #25913: Leading ``<~`` is optional now in base64.a85decode() with
+  adobe=True.  Patch by Swati Jaiswal.
+
 - Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
 
 - Issue #26367: importlib.__import__() raises SystemError like