Skip to content

Conversation

@ChALkeR
Copy link
Contributor

@ChALkeR ChALkeR commented Oct 10, 2025

If we are trusting the decoder at all, there is no reason to not trust it to thow on non-alphabet chars

The only place where spec behavior differs from the behavior wanted by this lib is ASCII whitespace

Before:

base64 (decode) 32 B scure x 2,881,844 ops/sec @ 347ns/op ± 7.01% (208ns..12ms)
base64 (decode) 64 B scure x 2,724,795 ops/sec @ 367ns/op ± 7.23% (208ns..11ms)
base64 (decode) 1 KB scure x 836,820 ops/sec @ 1μs/op ± 3.91% (958ns..7ms)
base64 (decode) 8 KB scure x 137,193 ops/sec @ 7μs/op
base64 (decode) 1 MB scure x 1,172 ops/sec @ 853μs/op

After:

base64 (decode) 32 B scure x 3,058,103 ops/sec @ 327ns/op ± 8.23% (166ns..17ms)
base64 (decode) 64 B scure x 3,184,713 ops/sec @ 314ns/op ± 8.32% (166ns..17ms)
base64 (decode) 1 KB scure x 1,923,076 ops/sec @ 520ns/op ± 7.34% (291ns..13ms)
base64 (decode) 8 KB scure x 535,045 ops/sec @ 1μs/op ± 2.80% (1μs..3ms)
base64 (decode) 1 MB scure x 6,576 ops/sec @ 152μs/op

Tests results are from Node.js 25 nightly, but behavior on other engines with native fromBase64 is similar

See:


Note

Invalid chars will now throw a SyntaxError instead of an Error
That's already the case for e.g. a==a though

If you want to normalize errors, that is doable with a try-catch

@paulmillr paulmillr merged commit f948c5a into paulmillr:main Oct 13, 2025
@ChALkeR ChALkeR mentioned this pull request Oct 14, 2025
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

Successfully merging this pull request may close these issues.

2 participants