jondavidjohn / payform

:credit_card: A library for building credit card forms, validating inputs, and formatting numbers.
https://jondavidjohn.github.io/payform/
Other
427 stars 81 forks source link

Clear control characters from expiry date string before parsing #50

Closed ddayguerrero closed 5 years ago

ddayguerrero commented 5 years ago

Changes

Fixes a parsing bug with the expiry field when typing in a RTL context. Since we are currently using a u200e control character to override the directionality of the card number and expiry date fields, it causes our month variable in payform.parseCardExpiry to return NaN.

> const expiryString = '\u200e'.concat('12/21');
<- undefined
> const expiryValues = expiryString.split('/');
<- undefined
> expiryValues
<- (2) ["‎12", "21"]
> const month = parseInt(expiryValues[0], 10);
<- undefined
> month
<- NaN

Why introduce these changes?

How is this achieved?