Skip to content

buffer: atob throw error when the input value is invalid#42662

Merged
aduh95 merged 6 commits intonodejs:masterfrom
austinkelleher:42646-buffer-validation
Apr 12, 2022
Merged

buffer: atob throw error when the input value is invalid#42662
aduh95 merged 6 commits intonodejs:masterfrom
austinkelleher:42646-buffer-validation

Conversation

@austinkelleher
Copy link
Copy Markdown
Contributor

@austinkelleher austinkelleher commented Apr 8, 2022

Description

The specification of atob has various different conditions that we need
to 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)):

atob(undefined)
VM85:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1

atob(false)
VM123:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1

atob(1)
VM152:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

atob(false)
VM187:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

atob(0)
VM217:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1

atob('a')
VM234:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1

atob('a ')
VM243:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1

atob(' a')
VM257:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1
    
atob('aaaaa')
VM283:1 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at <anonymous>:1:1

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atob should throw an error if the input is not correctly encoded

7 participants