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
Posted by Thomas Weidner (thomas) on 2009-07-02T09:42:41.000+0000
What is the value of $validName ?
Posted by Nelius (nelius.in) on 2009-07-02T12:00:49.000+0000
Code:
$validName = new Zend_Validate(); $validName->addValidator(new Zend_Validate_StringLength(1, 64)) ->addValidator(new Zend_Validate_Regex('/^[\p{L}]+$/u'));
Posted by Nelius (nelius.in) on 2009-07-02T12:08:36.000+0000
Same problem without validators.
Posted by Thomas Weidner (thomas) on 2009-07-02T12:12:08.000+0000
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.
Posted by Nelius (nelius.in) on 2009-07-02T12:19:11.000+0000
I'm using strongZend_Filter_StringTrimstrong. I'm not using Zend_Filter_StringLength at all.
Posted by Thomas Weidner (thomas) on 2009-07-02T12:42:11.000+0000
Using this example code I see no problems:
This means that the StringTrim filter DOES work with cyrillic text.
Posted by Thomas Weidner (thomas) on 2009-07-02T12:45:44.000+0000
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 ?
Posted by Nelius (nelius.in) on 2009-07-02T13:09:06.000+0000
I created empty file and put your code inside:
Result: null
Result: string 'Zend' (length=4)
Also i tried to use German: Gerüst
Result: string 'Gerüst' (length=7)
Very strange things...
Posted by Nelius (nelius.in) on 2009-07-02T13:09:46.000+0000
I created empty file and put your code inside:
Result: null
Result: string 'Zend' (length=4)
Also i tried to use German: Gerüst
Result: string 'Gerüst' (length=7)
Very strange things...
Posted by Nelius (nelius.in) on 2009-07-02T13:16:12.000+0000
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.
Posted by Thomas Weidner (thomas) on 2009-07-02T13:19:26.000+0000
Added unittest with r16417
Posted by Thomas Weidner (thomas) on 2009-07-02T13:27:34.000+0000
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.
Posted by Nelius (nelius.in) on 2009-07-02T13:47:01.000+0000
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!