Reputation: 801
I got a problem with an atob
that throws an exception
The string to be decoded is not correctly encoded.
There are already some questions like this on stack overflow but they deal about "complex" issues (file and/or URL encoding) my code is far simpler:
atob("MC4wNTgxMzA0OTg5OCAwLjA1NTU0MTg5OTA2IDEAA");
as the string length is 41 I tried to add 0,1,2 or 3 "=" with no luck.
The expected result (returned by any online base64 decoder I tested) is a plain string:
0.05813049898 0.05554189906 1
I tried dGVzdA==
or dGVzdA
and it is correctly decoded as "test".
So what's the obvious issue I should be ashamed of?
If this matters, I'm running Chromium 81.
PS: I just encoded the string back (Why I didn't think of it first?). And it looks like the encoded string should be
MC4wNTgxMzA0OTg5OCAwLjA1NTU0MTg5OTA2IDE=
which is decoded just fine.
atob("MC4wNTgxMzA0OTg5OCAwLjA1NTU0MTg5OTA2IDE=");
PS2: atob works just fine. It's juste the input string (and Apple) which is to blame according to http://www.monobjc.net/xib-file-format.html. So if ile file.length %4 == 1, I guess the answer is just to strip the last char. For 2 or 3 I don't know
Upvotes: 3
Views: 12875
Reputation: 5201
If you btoa
your expected result, you get:
console.log(btoa("0.05813049898 0.05554189906 1"));
which is different from your original string.
Upvotes: 3