diff --git a/src/IsoCodes/Insee.php b/src/IsoCodes/Insee.php index 57c746b..0076dcc 100644 --- a/src/IsoCodes/Insee.php +++ b/src/IsoCodes/Insee.php @@ -111,9 +111,9 @@ public static function validate($numero) $clef = 97 - fmod($aChecker, 97); if (empty($return['clef'])) { - $return['clef'] = $clef; // la clef est optionnelle, si elle n'est pas spécifiée, le numéro est valide, mais on rajoute la clef + $return['clef'] = sprintf('%02d', $clef); // la clef est optionnelle, si elle n'est pas spécifiée, le numéro est valide, mais on rajoute la clef } - if ((string) $clef !== (string) $return['clef']) { + if (sprintf('%02d', $clef) !== (string) $return['clef']) { return false; } diff --git a/tests/IsoCodes/Tests/InseeTest.php b/tests/IsoCodes/Tests/InseeTest.php index 91a06d1..63a6a95 100644 --- a/tests/IsoCodes/Tests/InseeTest.php +++ b/tests/IsoCodes/Tests/InseeTest.php @@ -31,6 +31,9 @@ public static function getInvalidValues() return [ ['353072B07300483'], ['253072C07300483'], + // Type juggling prevention + ['17702562600450x44'], + ['1770256260045 44'], ['177022A00100228'], // Wrong checksum ]; }