philnash / pwned

😱 An easy, Ruby way to use the Pwned Passwords API.
https://rubygems.org/gems/pwned/
MIT License
426 stars 22 forks source link

Don't raise TypeError if password is nil #9

Closed monfresh closed 6 years ago

monfresh commented 6 years ago

Hello. Thanks for this great gem! In my app, I am validating the presence of the password, but if it is nil, your gem is raising a TypeError, which is preventing the app from displaying a helpful message to the user asking them to fill in the password field.

Instead of raising an error, what do you think of adding an error to the record using the errors.add convention, with a message saying the password needs to be a String?

monfresh commented 6 years ago

I meant to say, only if the password is not nil, then add an error message saying it needs to be a String.

philnash commented 6 years ago

That's odd, I definitely tested this myself at one point and it was fine. Now I check again and it raises an error!

I think the validator itself just needs to return early with no extra errors if there is a nil or blank password. Other validations should cover the requirement for a password to be present.

philnash commented 6 years ago

Ok, this is fixed in version 1.2.1. Thanks for letting me know!