Skip to content

Commit 6c783ac

Browse files
Issue python#25913: Leading <~ is optional now in base64.a85decode() with adobe=True.
Patch by Swati Jaiswal.
2 parents 510addf + 205e75b commit 6c783ac

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎Lib/base64.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,15 @@ def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
366366
"""
367367
b = _bytes_from_decode_data(b)
368368
if adobe:
369-
if not (b.startswith(_A85START) and b.endswith(_A85END)):
370-
raise ValueError("Ascii85 encoded byte sequences must be bracketed "
371-
"by {!r} and {!r}".format(_A85START, _A85END))
372-
b = b[2:-2] # Strip off start/end markers
369+
if not b.endswith(_A85END):
370+
raise ValueError(
371+
"Ascii85 encoded byte sequences must end "
372+
"with {!r}".format(_A85END)
373+
)
374+
if b.startswith(_A85START):
375+
b = b[2:-2] # Strip off start/end markers
376+
else:
377+
b = b[:-2]
373378
#
374379
# We have to go through this stepwise, so as to ignore spaces and handle
375380
# special short sequences

‎Lib/test/test_base64.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ def test_a85decode(self):
494494
eq(base64.a85decode(data, adobe=False), res, data)
495495
eq(base64.a85decode(data.decode("ascii"), adobe=False), res, data)
496496
eq(base64.a85decode(b'<~' + data + b'~>', adobe=True), res, data)
497+
eq(base64.a85decode(data + b'~>', adobe=True), res, data)
497498
eq(base64.a85decode('<~%s~>' % data.decode("ascii"), adobe=True),
498499
res, data)
499500

@@ -584,8 +585,6 @@ def test_a85decode_errors(self):
584585
b"malformed", adobe=True)
585586
self.assertRaises(ValueError, base64.a85decode,
586587
b"<~still malformed", adobe=True)
587-
self.assertRaises(ValueError, base64.a85decode,
588-
b"also malformed~>", adobe=True)
589588

590589
# With adobe=False (the default), Adobe framing markers are disallowed
591590
self.assertRaises(ValueError, base64.a85decode,

‎Misc/NEWS‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ Core and Builtins
186186
Library
187187
-------
188188

189-
Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
189+
- Issue #25913: Leading ``<~`` is optional now in base64.a85decode() with
190+
adobe=True. Patch by Swati Jaiswal.
191+
192+
- Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
190193

191194
- Issue #26367: importlib.__import__() raises ImportError like
192195
builtins.__import__() when ``level`` is specified but without an accompanying

0 commit comments

Comments
 (0)