-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Improve "Leading padding not allowed" error in Base32 and Base64 decoders #148016
Copy link
Copy link
Open
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Previously it only was raised if "=" occurs at the start of the Base64 encoded data in strict mode. Now it is also raised for Base32 (always strict mode). If invalid "=" occurs after complete group, we get "Excess padding not allowed".
But now we have better control on what errors to ignore, we can ignore whitespace characters without ignoring bad "=". I think that if "=" is only preceded by ignored characters, without any alphabetical character, "Leading padding not allowed" is more correct than "Excess padding not allowed".
>>> import base64
>>> base64.b64decode(b'=abcd', ignorechars=b' ')
binascii.Error: Leading padding not allowed
>>> base64.b64decode(b' =abcd', ignorechars=b' ')
binascii.Error: Excess padding not allowedShould be:
>>> base64.b64decode(b' =abcd', ignorechars=b' ')
binascii.Error: Leading padding not allowedLinked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement