-
Notifications
You must be signed in to change notification settings - Fork 174
Description
I'm having a similar issue to #8, but I'm not sure if I've misunderstood something about how HashIds is supposed to work.
My test case is like so:
[TestMethod]
public void HashIdsBug()
{
var encoder = new Hashids("1234", 6, "ABCDEFGHIJKLMNOPQRSTUVWXY");
var decoded = encoder.Decode("ZZZZZZ");
}
This throws, because the Zs are not in the alphabet they end up being decoded to a negative number, and when Hashids tries to re-hash them to check the salt, it throws because it tries to index an array with a negative number.
I'm just not sure if this is by design? It's like this even on the hashids.org demo (if you change the variables to those above, it crashes). I would think that Hashids should be resistant to this sort of thing, same as decoding with the wrong salt.
If this is a bug, it can be fixed easily by either checking if any decoded numbers are < 0 before trying to re-encode them, or checking the input hash for any characters which aren't in the alphabet. @ullmark I'm happy to submit a pull request if you agree that this is broken.