@@ -48,32 +48,65 @@ public function testTrimSkipNonStrings()
48
48
}
49
49
50
50
/**
51
- * @dataProvider codePointProvider
51
+ * @dataProvider spaceProvider
52
52
*/
53
- public function testTrimUtf8 ( $ chars )
53
+ public function testTrimUtf8Separators ( $ hex )
54
54
{
55
55
if (!function_exists ('mb_check_encoding ' )) {
56
56
$ this ->markTestSkipped ('The "mb_check_encoding" function is not available ' );
57
57
}
58
58
59
- $ data = mb_convert_encoding (pack ('H* ' , implode ('' , $ chars )), 'UTF-8 ' , 'UCS-2BE ' );
60
- $ data = $ data ."ab \ncd " .$ data ;
59
+ // Convert hexadecimal representation into binary
60
+ // H: hex string, high nibble first (UCS-2BE)
61
+ // *: repeat until end of string
62
+ $ binary = pack ('H* ' , $ hex );
63
+
64
+ // Convert UCS-2BE to UTF-8
65
+ $ symbol = mb_convert_encoding ($ binary , 'UTF-8 ' , 'UCS-2BE ' );
66
+ $ symbol = $ symbol ."ab \ncd " .$ symbol ;
61
67
62
68
$ form = $ this ->getMock ('Symfony\Component\Form\Test\FormInterface ' );
63
- $ event = new FormEvent ($ form , $ data );
69
+ $ event = new FormEvent ($ form , $ symbol );
64
70
65
71
$ filter = new TrimListener ();
66
72
$ filter ->preSubmit ($ event );
67
73
68
- $ this ->assertSame ("ab \ncd " , $ event ->getData (), ' TrimListener should trim character(s): ' . implode ( ' , ' , $ chars ) );
74
+ $ this ->assertSame ("ab \ncd " , $ event ->getData ());
69
75
}
70
76
71
- public function codePointProvider ()
77
+ public function spaceProvider ()
72
78
{
73
79
return array (
74
- 'General category: Separator ' => array (array ('0020 ' , '00A0 ' , '1680 ' , '180E ' , '2000 ' , '2001 ' , '2002 ' , '2003 ' , '2004 ' , '2005 ' , '2006 ' , '2007 ' , '2008 ' , '2009 ' , '200A ' , '2028 ' , '2029 ' , '202F ' , '205F ' , '3000 ' )),
75
- 'General category: Other, control ' => array (array ('0009 ' , '000A ' , '000B ' , '000C ' , '000D ' , '0085 ' )),
76
- //'General category: Other, format. ZERO WIDTH SPACE' => array(array('200B')),
80
+ // separators
81
+ array ('0020 ' ),
82
+ array ('00A0 ' ),
83
+ array ('1680 ' ),
84
+ // array('180E'),
85
+ array ('2000 ' ),
86
+ array ('2001 ' ),
87
+ array ('2002 ' ),
88
+ array ('2003 ' ),
89
+ array ('2004 ' ),
90
+ array ('2005 ' ),
91
+ array ('2006 ' ),
92
+ array ('2007 ' ),
93
+ array ('2008 ' ),
94
+ array ('2009 ' ),
95
+ array ('200A ' ),
96
+ array ('2028 ' ),
97
+ array ('2029 ' ),
98
+ array ('202F ' ),
99
+ array ('205F ' ),
100
+ array ('3000 ' ),
101
+ // controls
102
+ array ('0009 ' ),
103
+ array ('000A ' ),
104
+ array ('000B ' ),
105
+ array ('000C ' ),
106
+ array ('000D ' ),
107
+ array ('0085 ' ),
108
+ // zero width space
109
+ // array('200B'),
77
110
);
78
111
}
79
112
}
0 commit comments