emn178/js-md5

Fix receive integer value

Closed this issue ยท 6 comments

Can you fix to receive integer value?
Just add a .toString() at parameter and up to bower?

why not do this before call method?

Because im migrating from another md5 library.

Hi @emn178

Please can you fix that integer value problem?

Hi,

I'm not sure this is good behavior. Imagine a situation that the user processed something and passed result to md5 function.

md5(expectToReturnString());

And it had a bug and returned a non-string result. He wouldn't know about this. This could be hard to debug.
I think it's better to throw an exception if input is not allowed.
Actually, current version doesn't throw exception and has this problem. So I prefer to change the behavior to raise exception rather than allow everything. Users should handle disallowed types before md5.

What do you think?

Automatically calling toString() could also mask bugs where a custom type is passed in, but its toString() is only used for pretty printing purposes. The user might assume everything is fine while not creating representational hashes for her objects. Therefore I would throw an error on any unsupported type.

v0.5.0 has changed the behavior. It will throw an error if input is incorrect.