Issues

ZF-7183: Zend_Filter_StringTrim does not work correctly with input which begins with a unicode char

Description

After last update from svn repository i have a bug using Zend_Filter_StringTrim.

I got an error "Invalid type given, value should be float, string, or integer" after having submitted a form with a Russian text. (Example: Зенд) I don't know about other languages, but everything is fine with a text in English.

Code is simple:

 
$name = new Zend_Form_Element_Text('name');
$name->setRequired(true)
             ->addValidator($validName)
             ->addFilter(new Zend_Filter_StringTrim());

If the last line is commented out, everything is ok.

Comments

What is the value of $validName ?

Code:

$validName = new Zend_Validate(); $validName->addValidator(new Zend_Validate_StringLength(1, 64)) ->addValidator(new Zend_Validate_Regex('/^[\p{L}]+$/u'));

Same problem without validators.

I don't see that you are using Zend_Filter_StringLength. Nor is this filter used by any validator you've used in the provided code.

I'm using strongZend_Filter_StringTrimstrong. I'm not using Zend_Filter_StringLength at all.

Using this example code I see no problems:


$filter = new Zend_Filter_StringTrim();
var_dump($filter->filter('Зенд'));

This means that the StringTrim filter DOES work with cyrillic text.

No reason to get loud.

Now that you've changed the issue report I see that you've used Zend_Form. Have you tried to reproduce this behaviour without Zend_Form ?

I created empty file and put your code inside:


$filter = new Zend_Filter_StringTrim();
var_dump($filter->filter('Зенд'));

Result: null


$filter = new Zend_Filter_StringTrim();
var_dump($filter->filter('Zend'));

Result: string 'Zend' (length=4)

Also i tried to use German: Gerüst

Result: string 'Gerüst' (length=7)

Very strange things...

I created empty file and put your code inside:


$filter = new Zend_Filter_StringTrim();
var_dump($filter->filter('Зенд'));

Result: null


$filter = new Zend_Filter_StringTrim();
var_dump($filter->filter('Zend'));

Result: string 'Zend' (length=4)

Also i tried to use German: Gerüst

Result: string 'Gerüst' (length=7)

Very strange things...

Next experiment...

File: Zend/Filter/StringTrim.php

LINE 112: return preg_replace("/$pattern/usSD", '', $value);

Works as expected without "u" modificator

LINE 112: return preg_replace("/$pattern/sSD", '', $value); - works.

Added unittest with r16417

I know... you should have tried with "Übung". Reason seems that the author of this component missed to test input which begins with a unicode char.

As you may have noted I've already added the proper unittest to check this behaviour with the mentioned release.

Yes, same problem with "Übung". :) Because of the error my registration form doesnt work.

I will edit this issue Summary: "Zend_Filter_StringTrim does not work correctly with input which begins with a unicode char"

Thank you for your help Thomas!