ZF-10337: Zend_Validate_Date doesn't validate time well

Description


$timeValidator = new Zend_Validate_Date(array('format' => 'HH:mm:ss'));                               
echo ($timeValidator->isValid('11:d5:00')) ? 'OK' : 'KO'; // output : OK !!
echo ($timeValidator->isValid('11:dd:00')) ? 'OK' : 'KO'; // output : KO

Comments

This is a difficult issue. I would probably force the date to be checked before it is passed to the Zend_Validate_Date class. But i agree the Zend_Validate_Date class should throw an exception when a non numeric value is found in the time (date) string.

The problem is caused by the following line in Zend_Locale_Format

preg_match_all('/\d+/u', $number, $splitted);

All non numeric values are stripped. This causes gaps when time strings like '12:dd:12' are given. And strings like '12:d5:12' will be validated because 'd5' evaluates to '5'

To solve the issue we could validate the date string before parsing it.