Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 205e75b

Browse files
Issue #25913: Leading <~ is optional now in base64.a85decode() with adobe=True.
Patch by Swati Jaiswal.
1 parent 1827eff commit 205e75b

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

Lib/base64.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,15 @@ def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
367367
"""
368368
b = _bytes_from_decode_data(b)
369369
if adobe:
370-
if not (b.startswith(_A85START) and b.endswith(_A85END)):
371-
raise ValueError("Ascii85 encoded byte sequences must be bracketed "
372-
"by {!r} and {!r}".format(_A85START, _A85END))
373-
b = b[2:-2] # Strip off start/end markers
370+
if not b.endswith(_A85END):
371+
raise ValueError(
372+
"Ascii85 encoded byte sequences must end "
373+
"with {!r}".format(_A85END)
374+
)
375+
if b.startswith(_A85START):
376+
b = b[2:-2] # Strip off start/end markers
377+
else:
378+
b = b[:-2]
374379
#
375380
# We have to go through this stepwise, so as to ignore spaces and handle
376381
# 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Core and Builtins
7676
Library
7777
-------
7878

79+
- Issue #25913: Leading ``<~`` is optional now in base64.a85decode() with
80+
adobe=True. Patch by Swati Jaiswal.
81+
7982
- Issue #26186: Remove an invalid type check in importlib.util.LazyLoader.
8083

8184
- Issue #26367: importlib.__import__() raises SystemError like

0 commit comments

Comments
 (0)