ZF-11239: Zend_Validate_EmailAddress should instantiate Zend_Validate_Hostname or completely ignore when not set

Issue Type: Bug Created: 2011-03-28T22:55:55.000+0000 Last Updated: 2012-02-26T07:32:36.000+0000 Status: Resolved Fix version(s): - 1.11.12 (22/Jun/12)

  • Next Major Release ()

Reporter: Gabriel Schuster (g.schuster) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

  • zf-crteam-review

Related issues: Attachments:


Currently Zend_Validate_EmailAddress does several calls on $this->options['hostname'] - whether set or not, resulting in fatal error "call to a member function on a non-object". In my opinion, a fatal error should _always be prevented, so either set a default hostname validator or ignore all portions where one would be needed.

Reproduce code:

<pre class="literal">
class FoobarController {
      public function indexAction() {
            $validator = new Zend_Validate_EmailAddress(array(
                  'mx'       => FALSE,
                  'deep'     => FALSE,
                  'domain'   => TRUE,
                  'messages' => array(
                        Zend_Validate_EmailAddress::INVALID             => 'Invalid blabla',
                        // more Zend_Validate_EmailAddress::-messages
                        Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE  => 'Can not...'

Suggested fix: all calls to $this->_options['hostname'] should be replaced by calls to $this->getHostnameValidator(), which checks for a set validator and instantiates one if requried.

<pre class="literal">
public function getHostnameValidator() {
      if(!(this->_options['hostname'] instanceof Zend_Validate_Hostname)) {
            // Should be enough as it already handles creation when passed NULL
      return $this->_options['hostname'];

Additionally, setOptions() should handle 'messages' option after 'hostname' option so one can pass in a hostname validator and let Validate_EmailAddress set messages to it. The current code would call setMessage() on the hostname validator before it is set or on the default (if the above fix is applied), but never on one specified in the options.

Checked version: SVN rev. 23772


Posted by Thomas Weidner (thomas) on 2011-08-25T21:51:01.000+0000

Fixed in ZF2 with GH-324

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-26T07:32:15.000+0000

Backported fix to ZFv1 in r24660 r24661

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.