Closed siiky closed 3 years ago
I guess the simple way to fix it would be:
hasSpace
which would be ALPHABET.indexOf(' ') >= 0
Let me know if you're willing to help. I might have time tomorrow.
Please see #78 and approve it.
Also test to make sure the base45 test vectors look sane to you.
Thanks.
Hey, thanks for the changes! Yes, I'll try it out today and report back.
A base45 (alphabet:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:
) message was failing to decode in version 3.0.8 with the "Non-base45 character" error. It didn't make any sense, because I confirmed the message did not include any non-base45 character, but later concluded the problem was that the encoded message started with a space.Through
git bisect
I found 2274e007d4535a7e3f8bfd50560cb0fb0b5e35bb to be the first "bad" commit (introduced in version 3.0.5) -- though I don't understand why just by reading the code. But looking at 3.0.8 the problem is more obvious:https://github.com/cryptocoinjs/base-x/blob/806ef3f473cb6c9a84559811f411b99cbcf93deb/src/index.js#L69-L70
It's not even "skipping" spaces at the start, it's rejecting them.
The problem seems to be decoding only, not encoding, and only messages that start with a space when encoded (from my very limited experiments). Versions >=3.0.5 correctly encode e.g. a dollar (
), but then error while decoding.
$
) as a space (And this is what I tried:
random.bin
was created withdd if=/dev/urandom of=random.bin bs=1K count=1
, and contained spaces in the middle of the encoded message, but not at the start.