Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error thrown on empty credit card number #161

Closed
seebees opened this issue Nov 13, 2014 · 1 comment · Fixed by #179
Closed

Error thrown on empty credit card number #161

seebees opened this issue Nov 13, 2014 · 1 comment · Fixed by #179
Assignees
Labels

Comments

@seebees
Copy link
Contributor

seebees commented Nov 13, 2014

validate.cardNumber() will throw TypeError: Cannot read property 'length' of undefined

You can fix this by changing:

https://github.com/recurly/recurly-js/blob/master/lib/util/parse-card.js#L10

to:

return (number || '').toString().replace(/[-\s]/g, '');

And someone should add a test at

describe('cardNumber', function () {

like:

   it('should return false for a null cardNumber', function() {
      assert(false === recurly.validate.cardNumber());
    });

Sure, a form should validate that you have a credit card number... but if someone tries to validate the form before putting anything in the number... it should just be false ;)

@chrissrogers
Copy link
Member

Thanks for reporting this and providing a solution. I'd be happy to get this fix into our next release -- and moreover, if you would like to build a PR for these changes, I'd be happy to accept the contribution.

Either way, it's definitely going in 👍

@chrissrogers chrissrogers self-assigned this Nov 21, 2014
chrissrogers added a commit that referenced this issue Jan 27, 2015
- instead of parseCard returning false, it returns an empty string that cardNumber can parse
- Fixes #161

Signed-off-by: Christopher Rogers <chrissrogers@gmail.com>
@bhelx bhelx closed this as completed in #179 Feb 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants