Zend Framework

Wrong error message for certain validators

Details

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

Description

Symptoms:

  • unexpected error messages from certain validators.

Example:
Zend_Validate_Regex has two errors: INVALID en NOT_MATCH. When the preg_match condition fails it returns the INVALID error and not the expected NOT_MATCH error. Resulting validation error message is "Invalid type given, value should be string, integer or float".

Cause of the problem:

  • some validators call function _error() of Zend_Validate_Abstract without parameters to indicate the validation condition has failed.
  • function Zend_Validate_Abstract::_error() without parameters takes the first message key from the $this->_messageTemplates array as 'the default error'.
  • the default error depends on the order of errors in the messageTemplates array, which is not necessarily always correct.

Affected validators with unexpected validation errors:

  • Zend_Validate_Regex
  • Zend_Validate_Hex
  • Zend_Validate_Float
  • Zend_Validate_Int
  • Zend_Validate_Ip

A number of other validators use the same technique but have only a single message:

  • Zend_Validate_GreaterThan
  • Zend_Validate_InArray
  • Zend_Validate_LessThan
  • Zend_Validate_Sitemap_Changefreq
    Which will probably cause problems when extending (and adding more messages).

Suggested solution:

  • always explicitly set the error key.

Activity

Hide
Thomas Weidner added a comment -

Fixed with r17469

Show
Thomas Weidner added a comment - Fixed with r17469

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: