summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-02-24 10:05:50 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-02-24 10:05:50 (GMT)
commit205e75bb629408d850efd6659c87ba1f8512b44b (patch)
tree694237abcab7e4ca0f458e2fe4f3e1658dceaf6d /Lib
parent1827eff03087d0e7975806967a68a349e10e5188 (diff)
downloadcpython-205e75bb629408d850efd6659c87ba1f8512b44b.zip
cpython-205e75bb629408d850efd6659c87ba1f8512b44b.tar.gz
cpython-205e75bb629408d850efd6659c87ba1f8512b44b.tar.bz2
Issue #25913: Leading <~ is optional now in base64.a85decode() with adobe=True.
Patch by Swati Jaiswal.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/base64.py13
-rw-r--r--Lib/test/test_base64.py3
2 files changed, 10 insertions, 6 deletions
diff --git a/Lib/base64.py b/Lib/base64.py
index e2c597b..adaec1d 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -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
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 9b853a8..4f86aaa 100644
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -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,