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

atob is less forgiving with padding than JSC, Node and browser based implementations #1379

Closed
2 tasks done
levibuzolic opened this issue Apr 23, 2024 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@levibuzolic
Copy link

Bug Description

  • I have run gradle clean and confirmed this bug does not occur with JSC
  • The issue is reproducible with the latest version of React Native.

Hermes git revision (if applicable): 6285c8b
React Native version: 0.74.0
OS: macOS

Steps To Reproduce

Before I dive into the issue, I wanted to thanks to the team for implementing btoa and atob, it's a great addition to the engine!

It's a common convention for Base64 strings to have their trailing padding = trimmed to make them compatible with URIs. For example the string "hello" would be encoded as aGVsbG8=, but can usually be trimmed down to aGVsbG8 and still be decoded correctly.

In JSC, Node, Chrome, Safari, Firefox:

atob("aGVsbG8=")
// "hello"

atob("aGVsbG8")
// "hello"

hermes appears to be quite strict with its validation of base64 strings and will fail on the second case:

atob("aGVsbG8=")
// "hello"

atob("aGVsbG8")
// Error: Not a valid base64 encoded string length

I also wanted to note that I'm not 100% sure if this is necessarily a bug, reading the spec for forgiving-base64 decode, I think it is. But if not, it's probably worth aligning the implementation to ensure compatibility.

@levibuzolic levibuzolic added the bug Something isn't working label Apr 23, 2024
@dannysu
Copy link
Contributor

dannysu commented Apr 23, 2024

@levibuzolic, thank you for the report. This does look like a bug. I'll work on a fix.

@dannysu
Copy link
Contributor

dannysu commented Apr 26, 2024

Fixed in Hermes with 0888914

@dannysu dannysu closed this as completed Apr 26, 2024
@levibuzolic
Copy link
Author

@dannysu thanks so much for jumping on this so quickly. 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants