ZF-6033: Zend_Validate_Hostname accepting invalid TLD


Not sure if is a bug (not very informed about TLDs), but you will get invalid domains TLD accepted as long as end with a valid TLD and are separated with non alpha chars like numbers in Zend_Validate_Hostname

For example if you try to validate: www.danguer1com Zend_Validate_Hostname will set as valid.

I think the problem is on valid() function on this line: if (preg_match('/([a-z]{2,10})$/i', end($domainParts), $matches)) {

You are reading the last chars, but instead it should be: if (preg_match('/^([a-z]{2,10})$/i', end($domainParts), $matches)) {

To match all the chars instead last, this way danguercom will set as invalid

Example code: <?php require_once 'Zend/Validate/Hostname.php';

$tests = array( 'www.danguer1com', 'www.danguercom', 'www.danguer-com', 'danguer1com', 'danguer1-com', 'www.danguer1de', 'asd.danguer-it' );

$validator = new Zend_Validate_Hostname();

foreach($tests as $test) { print "Testing {$test}: ".$validator->isValid($test)."\n"; }

Results: Testing www.danguer1com: 1 Testing www.danguercom: Testing www.danguer-com: 1 Testing danguer1com: Testing danguer1-com: Testing www.danguer1de: 1 Testing asd.danguer-it: 1

Expected results: All being blank after domain name (false)


Fixed with r14543