-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
buffer: atob throw error when the input value is invalid #42662
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
Conversation
a924347 to
473c352
Compare
|
Additional note - I'm happy to split this change into multiple PRs if it's helpful. 😄 |
473c352 to
2ad1a00
Compare
It should be converted to a string, so atob(1234) === '×mø'is correct |
|
@zloirock Thank you for catching...I'll update the PR. |
The specification of `atob` has various different conditions that we need to abide by. The specific changes that were made: * `atob` now immediately throws when `undefined`, `false`, or a `number` is supplied * `atob` now strips ASCII whitespace before attempting to decode * `atob` now validates that the code point's length divided by 4 leaves a remainder that is not 1 See: https://infra.spec.whatwg.org/#forgiving-base64-decode Fixes: nodejs#42646
* Use approach of counting non-ASCII whitespace characters instead of removing the characters via string replacement * Additional atob validation tests have been added
1c109ce to
08e4c75
Compare
* Chrome and Firefox both use `InvalidCharacterError` when the string to be decoded is not correctly encoded * Remove unnecessary atob test
aduh95
left a comment
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: we could keep one array and save a lookup per char.Given the fact that this is a legacy API for which performance are not really a concern, you can ignore this suggestion if you think it makes the code harder to read.
* Small optimization in atob validation by assuming positions of whitespace characters in allowed chars array * Improved tests for ASCII whitespace characters * Explicitly validate properties of `DOMException` in tests
689d51f to
a5828d8
Compare
|
It seems that some of the tests may have failed intermittently unless I'm missing something. Anything that I'm missing? If not, can someone please re-trigger? Thanks! |
|
It looks like all checks have passed except for the pending |
|
Landed in 7533d08, thanks for the contribution 🎉 |
|
@austinkelleher should this land in v16.x? If so, do you mind creating a backport PR for this to v16.x-staging? (docs) Thanks! |
Description
The specification of
atobhas various different conditions that we needto abide by.
See: https://infra.spec.whatwg.org/#forgiving-base64-decode
Fixes: #42646
Considerations
Each of the new cases that are handled added could be considered breaking changes. Consider the following tests run directly from the Chrome console (Version 100.0.4896.75 (Official Build) (arm64)):