Skip to content

Commit 1a64fef

Browse files
committed
bug symfony#10872 [Form] Fixed TrimListenerTest as of PHP 5.5 (webmozart)
This PR was merged into the 2.3 branch. Discussion ---------- [Form] Fixed TrimListenerTest as of PHP 5.5 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- b0bc83d [Form] Fixed TrimListenerTest as of PHP 5.5
2 parents 894b4a0 + b0bc83d commit 1a64fef

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,65 @@ public function testTrimSkipNonStrings()
4848
}
4949

5050
/**
51-
* @dataProvider codePointProvider
51+
* @dataProvider spaceProvider
5252
*/
53-
public function testTrimUtf8($chars)
53+
public function testTrimUtf8Separators($hex)
5454
{
5555
if (!function_exists('mb_check_encoding')) {
5656
$this->markTestSkipped('The "mb_check_encoding" function is not available');
5757
}
5858

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;
6167

6268
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
63-
$event = new FormEvent($form, $data);
69+
$event = new FormEvent($form, $symbol);
6470

6571
$filter = new TrimListener();
6672
$filter->preSubmit($event);
6773

68-
$this->assertSame("ab\ncd", $event->getData(), 'TrimListener should trim character(s): '.implode(', ', $chars));
74+
$this->assertSame("ab\ncd", $event->getData());
6975
}
7076

71-
public function codePointProvider()
77+
public function spaceProvider()
7278
{
7379
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'),
77110
);
78111
}
79112
}

0 commit comments

Comments
 (0)