commenthol/url-safe-base64

isBase64() and isUrlSafeBase64() not properly testing

Closed this issue · 4 comments

It seems I can give isBase64() and isUrlSafeBase64() any string of letters and numbers and they still return true, even when the string is neither Base64 nor URL-safe Base64.

isBase64('abc123');
// true

isUrlSafeBase64('abc123');
// true

@theDanielJLewis abc123 is a properly encoded base64 string, which is also url-safe.
Can you please better explain what you'd expect from the functions to return?

abc123 doesn't decode to anything, so I wouldn't consider it valid base64. While a comparing function could be handy, it would require knowledge of the original string, which might not always be available, and would still not solve the issue of these two is… functions returning true for seemingly any input that doesn't contain special characters.

abc123 decodes to 0x69, 0xb7, 0x35, 0xdb, not sure what the problem here is

Strange. When I enter abc123 into https://www.base64decode.net/, it decodes to nothing.

It just seems like the is… functions are doing nothing more than checking for special characters.

But I get the impression this isn't something you're interested in improving. So I'll close this and find another solution.