Skip to content

Commit dea4982

Browse files
gpsheadclaude
andcommitted
Update docs for base85/ascii85 canonical and 1-char group changes
- Document that single-character final groups are always rejected - Add versionchanged:: next markers for the behavioral change - Update canonical= description for ascii85 to mention z-abbreviation - Update canonical= description for base85 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2a1d91d commit dea4982

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

Doc/library/base64.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ Refer to the documentation of the individual functions for more information.
345345

346346
.. versionchanged:: next
347347
Added the *canonical* parameter.
348+
Single-character final groups are now always rejected as encoding
349+
violations.
348350

349351

350352
.. function:: b85encode(b, pad=False, *, wrapcol=0)
@@ -381,6 +383,8 @@ Refer to the documentation of the individual functions for more information.
381383

382384
.. versionchanged:: next
383385
Added the *ignorechars* and *canonical* parameters.
386+
Single-character final groups are now always rejected as encoding
387+
violations.
384388

385389

386390
.. function:: z85encode(s, pad=False, *, wrapcol=0)
@@ -421,6 +425,8 @@ Refer to the documentation of the individual functions for more information.
421425

422426
.. versionchanged:: next
423427
Added the *ignorechars* and *canonical* parameters.
428+
Single-character final groups are now always rejected as encoding
429+
violations.
424430

425431

426432
.. _base64-legacy:

Doc/library/binascii.rst

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ The :mod:`!binascii` module defines the following functions:
119119
Convert Ascii85 data back to binary and return the binary data.
120120

121121
Valid Ascii85 data contains characters from the Ascii85 alphabet in groups
122-
of five (except for the final group, which may have from two to five
122+
of five (except for the final group, which may have from two to four
123123
characters). Each group encodes 32 bits of binary data in the range from
124124
``0`` to ``2 ** 32 - 1``, inclusive. The special character ``z`` is
125125
accepted as a short form of the group ``!!!!!``, which encodes four
126-
consecutive null bytes.
126+
consecutive null bytes. A single-character final group is always rejected
127+
as an encoding violation.
127128

128129
*foldspaces* is a flag that specifies whether the 'y' short sequence
129130
should be accepted as shorthand for 4 consecutive spaces (ASCII 0x20).
@@ -136,15 +137,20 @@ The :mod:`!binascii` module defines the following functions:
136137
to ignore from the input.
137138
This should only contain whitespace characters.
138139

139-
If *canonical* is true, non-canonical encodings in the final group are
140-
rejected with :exc:`binascii.Error`. This includes single-character
141-
final groups (which no conforming encoder produces) and final groups whose
142-
padding digits are not what the encoder would produce.
140+
If *canonical* is true, non-canonical encodings are rejected with
141+
:exc:`binascii.Error`. This enforces that the ``z`` abbreviation is used
142+
for all-zero groups (rather than ``!!!!!``), and that partial final groups
143+
use the same padding digits the encoder would produce.
143144

144145
Invalid Ascii85 data will raise :exc:`binascii.Error`.
145146

146147
.. versionadded:: 3.15
147148

149+
.. versionchanged:: next
150+
Single-character final groups are now always rejected as encoding
151+
violations. Previously they were silently ignored, producing no output
152+
bytes.
153+
148154

149155
.. function:: b2a_ascii85(data, /, *, foldspaces=False, wrapcol=0, pad=False, adobe=False)
150156

@@ -175,25 +181,30 @@ The :mod:`!binascii` module defines the following functions:
175181
More than one line may be passed at a time.
176182

177183
Valid Base85 data contains characters from the Base85 alphabet in groups
178-
of five (except for the final group, which may have from two to five
184+
of five (except for the final group, which may have from two to four
179185
characters). Each group encodes 32 bits of binary data in the range from
180-
``0`` to ``2 ** 32 - 1``, inclusive.
186+
``0`` to ``2 ** 32 - 1``, inclusive. A single-character final group is
187+
always rejected as an encoding violation.
181188

182189
Optional *alphabet* must be a :class:`bytes` object of length 85 which
183190
specifies an alternative alphabet.
184191

185192
*ignorechars* should be a :term:`bytes-like object` containing characters
186193
to ignore from the input.
187194

188-
If *canonical* is true, non-canonical encodings in the final group are
189-
rejected with :exc:`binascii.Error`. This includes single-character
190-
final groups (which no conforming encoder produces) and final groups whose
191-
padding digits are not what the encoder would produce.
195+
If *canonical* is true, non-canonical encodings in partial final groups
196+
are rejected with :exc:`binascii.Error`. This enforces that the padding
197+
digits match what the encoder would produce.
192198

193199
Invalid Base85 data will raise :exc:`binascii.Error`.
194200

195201
.. versionadded:: 3.15
196202

203+
.. versionchanged:: next
204+
Single-character final groups are now always rejected as encoding
205+
violations. Previously they were silently ignored, producing no output
206+
bytes.
207+
197208

198209
.. function:: b2a_base85(data, /, *, alphabet=BASE85_ALPHABET, wrapcol=0, pad=False)
199210

0 commit comments

Comments
 (0)