-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] Add a new validate
parameter to the b64decode()
function
#3929
Conversation
Signed-off-by: Manuel Saelices <[email protected]>
validate
parameter to the b64decode()
function
Signed-off-by: Manuel Saelices <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, happy to sync it once the minor comments are addressed. Thanks!
stdlib/src/base64/base64.mojo
Outdated
@parameter | ||
if validate: | ||
if n % 4 != 0: | ||
raise Error("ValueError: Input length must be divisible by 4") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion Include the byte length value (n
) in the error message.
stdlib/src/base64/base64.mojo
Outdated
@parameter | ||
if validate: | ||
if a < 0 or b < 0 or c < 0 or d < 0: | ||
raise Error("ValueError: Unexpected character encountered") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion Include the unexpected character value in the error message.
This may mean pulling the snippet out into a local function and call it for each of the values a
, b
, c
, and d
.
Signed-off-by: Manuel Saelices <[email protected]>
Thanks. I've fixed both of them here: msaelices@c1873d6 Could you please TAL? |
Nice improvement, thanks! Syncing now. |
!sync |
@msaelices do you mind rebasing with latest nightly so I can sync this? Thanks! |
done |
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the main branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
Landed in 9c6d9fa! Thank you for your contribution 🎉 |
…)` function (#54857) [External] [stdlib] Add a new `validate` parameter to the `b64decode()` function Matching the `validate` bool argument in Python's [base64.b64decode](https://docs.python.org/3/library/base64.html#base64.b64decode) but a using comp time parameter so it will not add CPU cycles if validation is not needed. Co-authored-by: Manuel Saelices <[email protected]> Closes #3929 MODULAR_ORIG_COMMIT_REV_ID: 10ee9bb8c9b339c8360afc75f2f28717188e954d
Matching the
validate
bool argument in Python's base64.b64decode but a using comp time parameter so it will not add CPU cycles if validation is not needed.