cryptocoinjs / base-x

Encode/decode any base
MIT License
312 stars 75 forks source link

encode input validation #48

Closed wraithgar closed 6 years ago

wraithgar commented 6 years ago

The encode function assumes you are passing in a Buffer, but will happily accept a string with no errors. It will also return a valid looking result that does not decode back into the original string.

It would be helpful if this library threw some sort of exception back to the user if they passed an invalid input to the encode function.

dcousens commented 6 years ago

@wraithgar I suppose the intention was to support anything that supported indexing. Array-like...

It doesn't help that 2[0] === undefined... ha.

wraithgar commented 6 years ago

Yeah I figured there was some broader set of things that were intended to work otherwise I'd have made a PR. The fact remains that there are inputs that will silently produce bad output. Perhaps just a "not a string" test would be enough.

dcousens commented 6 years ago

@wraithgar I'm OK with restricting it to Array and Buffer, but I think I have seen usage with string :confused: , but a major bump wouldn't be out of the question if that is the case.

dcousens commented 6 years ago

https://github.com/cryptocoinjs/base-x/commit/6cbf08a7d7ddc51bb1055cedc60a4dd9371ee433