Skip to content

Commit 00fb6fc

Browse files
committed
Address PR review nits: doc ordering, partial-group wording, NEWS, whatsnew
- Reorder versionchanged param lists alphabetically in base64.rst and binascii.rst (canonical, ignorechars, padded). - Restore "two to five" in a2b_ascii85/a2b_base85 partial-group text; partial finals are 2-4 chars but a complete final group is 5. - Drop redundant versionchanged blocks from a2b_ascii85/a2b_base85 since both functions are new in 3.15. - Add Misc/NEWS.d entry and Doc/whatsnew/3.15.rst bullets covering the new canonical kwarg and the unconditional 1-char rejection.
1 parent ea1afef commit 00fb6fc

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

Doc/library/base64.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ POST request.
118118
For more information about the strict base64 check, see :func:`binascii.a2b_base64`
119119

120120
.. versionchanged:: 3.15
121-
Added the *ignorechars*, *padded*, and *canonical* parameters.
121+
Added the *canonical*, *ignorechars*, and *padded* parameters.
122122

123123
.. deprecated:: 3.15
124124
Accepting the ``+`` and ``/`` characters with an alternative alphabet
@@ -216,7 +216,7 @@ POST request.
216216
input.
217217

218218
.. versionchanged:: 3.15
219-
Added the *ignorechars*, *padded*, and *canonical* parameters.
219+
Added the *canonical*, *ignorechars*, and *padded* parameters.
220220

221221

222222
.. function:: b32hexencode(s, *, padded=True, wrapcol=0)
@@ -243,7 +243,7 @@ POST request.
243243
.. versionadded:: 3.10
244244

245245
.. versionchanged:: 3.15
246-
Added the *ignorechars*, *padded*, and *canonical* parameters.
246+
Added the *canonical*, *ignorechars*, and *padded* parameters.
247247

248248

249249
.. function:: b16encode(s, *, wrapcol=0)
@@ -384,7 +384,7 @@ Refer to the documentation of the individual functions for more information.
384384
.. versionadded:: 3.4
385385

386386
.. versionchanged:: 3.15
387-
Added the *ignorechars* and *canonical* parameters.
387+
Added the *canonical* and *ignorechars* parameters.
388388
Single-character final groups are now always rejected as encoding
389389
violations.
390390

@@ -426,7 +426,7 @@ Refer to the documentation of the individual functions for more information.
426426
.. versionadded:: 3.13
427427

428428
.. versionchanged:: 3.15
429-
Added the *ignorechars* and *canonical* parameters.
429+
Added the *canonical* and *ignorechars* parameters.
430430
Single-character final groups are now always rejected as encoding
431431
violations.
432432

Doc/library/binascii.rst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The :mod:`!binascii` module defines the following functions:
9191
Added the *strict_mode* parameter.
9292

9393
.. versionchanged:: 3.15
94-
Added the *alphabet*, *ignorechars*, *padded*, and *canonical* parameters.
94+
Added the *alphabet*, *canonical*, *ignorechars*, and *padded* parameters.
9595

9696

9797
.. function:: b2a_base64(data, *, padded=True, alphabet=BASE64_ALPHABET, wrapcol=0, newline=True)
@@ -122,7 +122,7 @@ The :mod:`!binascii` module defines the following functions:
122122
Convert Ascii85 data back to binary and return the binary data.
123123

124124
Valid Ascii85 data contains characters from the Ascii85 alphabet in groups
125-
of five (except for the final group, which may have from two to four
125+
of five (except for the final group, which may have from two to five
126126
characters). Each group encodes 32 bits of binary data in the range from
127127
``0`` to ``2 ** 32 - 1``, inclusive. The special character ``z`` is
128128
accepted as a short form of the group ``!!!!!``, which encodes four
@@ -149,11 +149,6 @@ The :mod:`!binascii` module defines the following functions:
149149

150150
.. versionadded:: 3.15
151151

152-
.. versionchanged:: next
153-
Single-character final groups are now always rejected as encoding
154-
violations. Previously they were silently ignored, producing no output
155-
bytes.
156-
157152

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

@@ -184,7 +179,7 @@ The :mod:`!binascii` module defines the following functions:
184179
More than one line may be passed at a time.
185180

186181
Valid Base85 data contains characters from the Base85 alphabet in groups
187-
of five (except for the final group, which may have from two to four
182+
of five (except for the final group, which may have from two to five
188183
characters). Each group encodes 32 bits of binary data in the range from
189184
``0`` to ``2 ** 32 - 1``, inclusive. A single-character final group is
190185
always rejected as an encoding violation.
@@ -203,11 +198,6 @@ The :mod:`!binascii` module defines the following functions:
203198

204199
.. versionadded:: 3.15
205200

206-
.. versionchanged:: next
207-
Single-character final groups are now always rejected as encoding
208-
violations. Previously they were silently ignored, producing no output
209-
bytes.
210-
211201

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

Doc/whatsnew/3.15.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,15 @@ base64
729729
:func:`~base64.z85decode`.
730730
(Contributed by Serhiy Storchaka in :gh:`144001` and :gh:`146431`.)
731731

732+
* Added the *canonical* parameter in
733+
:func:`~base64.b32decode`, :func:`~base64.b32hexdecode`,
734+
:func:`~base64.b64decode`, :func:`~base64.urlsafe_b64decode`,
735+
:func:`~base64.a85decode`, :func:`~base64.b85decode`, and
736+
:func:`~base64.z85decode`,
737+
to reject encodings with non-zero padding bits or other non-canonical
738+
forms.
739+
(Contributed by Gregory P. Smith in :gh:`146311`.)
740+
732741

733742
binascii
734743
--------
@@ -762,6 +771,10 @@ binascii
762771
:func:`~binascii.unhexlify`, and :func:`~binascii.a2b_base64`.
763772
(Contributed by Serhiy Storchaka in :gh:`144001` and :gh:`146431`.)
764773

774+
* Added the *canonical* parameter in :func:`~binascii.a2b_base64`,
775+
to reject encodings with non-zero padding bits.
776+
(Contributed by Gregory P. Smith in :gh:`146311`.)
777+
765778

766779
calendar
767780
--------
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Add a *canonical* keyword-only parameter to the base16, base32, base64,
2+
base85, ascii85, and Z85 decoders in :mod:`base64` and :mod:`binascii`.
3+
When true, encodings with non-zero padding bits (base16/32/64) or
4+
non-canonical encodings (base85/ascii85) are rejected. Single-character
5+
final groups in :func:`binascii.a2b_ascii85` and :func:`binascii.a2b_base85`
6+
are now always rejected as encoding violations, regardless of *canonical*;
7+
previously they were silently ignored and produced no output bytes.

0 commit comments

Comments
 (0)