Skip to content
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

Ignore padding on decode #45

Open
oliverjanik opened this issue Jul 11, 2018 · 2 comments
Open

Ignore padding on decode #45

oliverjanik opened this issue Jul 11, 2018 · 2 comments

Comments

@oliverjanik
Copy link

oliverjanik commented Jul 11, 2018

Strictly speaking the '=' characters do not carry any information. Can decode ignore missing padding and not throw an error?

Hello downvoters, care to explain your reasoning?

@qgustavor
Copy link

From those lines in the code seems URL-safe base64 strings are supported, but if padding is required then those aren't supported as some variants don't use it.

Node supports decoding URL-safe base64 strings without padding. Example: Buffer.from('HI', 'base64') return "<Buffer 1c>". base64js.toByteArray('HI') throws "Invalid string. Length must be a multiple of 4".

@eugene1g
Copy link

eugene1g commented Mar 13, 2022

As a workaround, I re-inject any missing padding before passing the text to this library, like so -

let b64 = "AAAAAAA"; // base64-encoded text that could be missing padding
if( (b64.length % 4) !== 0) b64 += "=".repeat(4 - (b64.length % 4))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants