lucavandro / CodiceFiscaleJS

CodiceFiscale.js is a utility library to compute and validate Italian Tax code (codice fiscale).
Creative Commons Attribution Share Alike 4.0 International
197 stars 77 forks source link

Validation is case sensitive #21

Closed mbilotta closed 5 years ago

mbilotta commented 5 years ago

Bug is here:

https://github.com/lucavandro/CodiceFiscaleJS/blob/520533431d73e51b1550454780f5fe6927aa9b07/src/codice-fiscale.js#L78-L84

Check fails because you're giving away the uppercase codice fiscale at line 83.

I'd rewrite that piece like this:

let cf = codiceFiscale.toUpperCase();
if (cf.length !== 16) { 
   return false 
}
const expectedCheckCode = cf.charAt(15);
return CodiceFiscale.getCheckCode(cf.slice(0, 15)) === expectedCheckCode 
lucavandro commented 5 years ago

thank you for your report. The issue is now fixed. Please upgrade to v2.2.2