ZF-11863: Validation fails using 'à' char

Issue Type: Bug Created: 2011-10-31T16:33:50.000+0000 Last Updated: 2012-05-28T19:56:47.000+0000 Status: Resolved Fix version(s): - Next Major Release ()

Reporter: Aurelio De Rosa (aurelioderosa) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


I've created a form using the following code to add an input element:

<pre class="highlight">
$Element = new Zend_Form_Element_Text('field');
    new Zend_Validate_Regex('/^[[:alpha:]\']+$/iu'),
    new Zend_Validate_StringLength(array('min' => 3, 'max' => 50))));
$Element->addFilters(array(new Zend_Filter_StringTrim()));

This is a summary of what I input in the field, what I should got and what I really got. ||Input||Expected||Gotten|| |test|true|true| |test99|false|false| |òèùtestòò|true|true| |testà|true|"There was an internal error while using the pattern '/^[[:alpha:]\']+$/iu'"| |teààst|true|true| |ààòòìùéé|true|true| |èùòìiieeà|true|"There was an internal error while using the pattern '/^[[:alpha:]\']+$/iu'"|

Moreover, if I try to run the input in a normal preg_match, I got the expected results as shown in the following table: ||Input||Expected||Gotten|| |test|true|true| |test99|false|false| |òèùtestòò|true|true| |testà|true|true| |teààst|true|true| |ààòòìùéé|true|true| |èùòìiieeà|true|true|

As you can see, the validator seems to fail when the 'à' is at the end of the string. The same weird behavior can be seen using the Zend_Validate_Alpha too. In this case, sometimes, the view shows an empty error string. I mean that it will show the list tag (li) as he wants to show an error, but this one is empty.

Note: I found that the problem is exactly in this method of the Zend_Filter_StringTrim

<pre class="highlight">
    protected function _unicodeTrim($value, $charlist = '\\\\s')
    { // here the value it's ok
        $chars = preg_replace(
            array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'),
            array( '\\\\\\0', '\\', '\/' ),

        $pattern = '^[' . $chars . ']*|[' . $chars . ']*$';
        return preg_replace("/$pattern/sSD", '', $value);  // here the last à (a multibyte char) has been truncated


Posted by Thomas Weidner (thomas) on 2011-11-11T20:53:20.000+0000

Added related unittests with GH-592... no failure reproduceable for the validator

Posted by Aurelio De Rosa (aurelioderosa) on 2011-11-16T19:52:11.000+0000

I found the exact method where the issue came (and I've updated the post). I don't know if it has been fixed in ZF2.

Posted by Thomas Weidner (thomas) on 2011-11-17T13:29:52.000+0000

When the failure does not occur with ZF2 it must have been fixed in past.

Posted by Aurelio De Rosa (aurelioderosa) on 2011-11-17T13:34:01.000+0000

I found that the problem I've reported is a duplicate of this issue:

Posted by Maks 3w (maks3w) on 2012-05-28T19:56:46.000+0000

This occurs due a PHP bug for versions lower than v5.3.4 (

As a workaround you can set the locale (setlocale) with a locale that supports the characters.

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.