Zend Framework

Zend_Validate_Regex uses incorrect message template

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9.1
  • Fix Version/s: 1.9.2
  • Component/s: Zend_Validate
  • Labels:
    None

Description

Code to reproduce error

In the output of the code fragment below is visible that Zend_Validate_Regex uses Zend_Validate_Regex::INVALID message template, instead of Zend_Validate_Regex::NOT_MATCH template.

$validator = new Zend_Validate_Regex('/^\d+$/');
if(!$validator->isValid('this is not digit'))
{
	foreach($validator->getMessages() as $message)
	{
		$message_template = $validator->getMessageTemplates();
		$message_template = $message_template[Zend_Validate_Regex::NOT_MATCH];
		
		echo $message_template;
		echo "\n<br/>";
		echo $message;
	}
}

The cause

$this->_error() call (at line 120) in Zend_Validate_Regex::isValid function uses first available message template, which in this case is Zend_Validate_Regex::INVALID.


The solution:

in Zend_Validate_Regex::isValid function instead of lines (119-122), just before last return statement

if (!$status) {
	$this->_error();
	return false;
}

should be

if (!$status) {
	$this->_error(self::NOT_MATCH);
	return false;
}

Activity

Hide
Thomas Weidner added a comment -

This is a duplication of an existing issue and has already been fixed with ZF 1.9.2

Show
Thomas Weidner added a comment - This is a duplication of an existing issue and has already been fixed with ZF 1.9.2

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: