You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an interesting issue. The test string provided is not strictly valid base64 as it is missing padding and not a multiple of 4 characters. So in one sense the issue is that Bun is silently failing here and returning an incorrect length. A "true" fix would be to use base64url as your encoding type. However... Node is more permissive and silently allows missing padding characters, see this issue thread. So in the interest of matching Node's behavior, I think we need to make our decoder permissive of missing padding and whitespace.
And it looks like the decoder is already permissive, so it's just a matter of ensuring that the length calculation is permissive of potentially missing padding.
What version of Bun is running?
0.5.6
What platform is your computer?
Linux ip-172-26-7-81 5.4.0-1018-aws #18-Ubuntu SMP Wed Jun 24 01:15:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
What steps can reproduce the bug?
// b.js
let x = Buffer.from("eyJlbWFpbCI6Ijg3MTg4NDYxN0BxcS5jb20iLCJpZCI6OCwicm9sZSI6Im5vcm1hbCIsImlhdCI6MTY3NjI4NDQyMSwiZXhwIjoxNjc2ODg5MjIxfQ", 'base64'); console.log(x.length, x[82], x[83], x[84]); console.log(x.toString('utf-8'));
// bun run b.js
What is the expected behavior?
85 50 49 125
{"email":"871884617@qq.com","id":8,"role":"normal","iat":1676284421,"exp":1676889221}
What do you see instead?
84 50 49 undefined
{"email":"871884617@qq.com","id":8,"role":"normal","iat":1676284421,"exp":1676889221
Additional information
No response
The text was updated successfully, but these errors were encountered: