JamesEggers1 / luhn

A JavaScript module of the luhn algorithm for Credit Card Validation that works with both client-side JavaScript and Node.js
MIT License
52 stars 17 forks source link

Fix for empty string returning true during validation #15

Closed JonathanPorta closed 5 years ago

JonathanPorta commented 5 years ago

Problem: passing the value '' to validate() results in a return value of true.

Solution: remove a length check that was returning true for a length of 0.

NOTE: I was really trying to find a reason as to why you would want to return true for an empty string but I couldn't think of a reason. I concluded that this was possibly leftover code that was no longer needed. (git blame showed it being added over four years ago)

Thanks for publishing and maintaing a great helper library!

JamesEggers1 commented 5 years ago

Thanks for the PR. It looks pretty straight-forward, and I cannot for the life of me remember why I put that. Only thing I can think of is that it was part of the actual Luhn algorithm definition. Regardless, I'll try and get this merged in and a new version of the NPM module pushed in the coming days.

Thanks again!

JamesEggers1 commented 5 years ago

Merged into the main codebase. Update is a part of luhn package 2.4. Thanks again for the pull request!