Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3ee005

Browse files
committed
[Form] updated CHANGELOG.md
1 parent 351174b commit f3ee005

File tree

5 files changed

+117
-68
lines changed

5 files changed

+117
-68
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* added the html5 "range" FormType
99
* deprecated the "cascade_validation" option in favor of setting "constraints"
1010
with the Valid constraint
11+
* moved data trimming logic of TrimListener into StringUtil
1112

1213
2.7.0
1314
-----

src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\FormEvents;
1515
use Symfony\Component\Form\FormEvent;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17+
use Symfony\Component\Form\Util\StringUtil;
1718

1819
/**
1920
* Trims string data.
@@ -30,11 +31,7 @@ public function preSubmit(FormEvent $event)
3031
return;
3132
}
3233

33-
if (null !== $result = @preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $data)) {
34-
$event->setData($result);
35-
} else {
36-
$event->setData(trim($data));
37-
}
34+
$event->setData(StringUtil::trim($data));
3835
}
3936

4037
/**

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

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,67 +39,4 @@ public function testTrimSkipNonStrings()
3939

4040
$this->assertSame(1234, $event->getData());
4141
}
42-
43-
/**
44-
* @dataProvider spaceProvider
45-
*/
46-
public function testTrimUtf8Separators($hex)
47-
{
48-
if (!function_exists('mb_convert_encoding')) {
49-
$this->markTestSkipped('The "mb_convert_encoding" function is not available');
50-
}
51-
52-
// Convert hexadecimal representation into binary
53-
// H: hex string, high nibble first (UCS-2BE)
54-
// *: repeat until end of string
55-
$binary = pack('H*', $hex);
56-
57-
// Convert UCS-2BE to UTF-8
58-
$symbol = mb_convert_encoding($binary, 'UTF-8', 'UCS-2BE');
59-
$symbol = $symbol."ab\ncd".$symbol;
60-
61-
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
62-
$event = new FormEvent($form, $symbol);
63-
64-
$filter = new TrimListener();
65-
$filter->preSubmit($event);
66-
67-
$this->assertSame("ab\ncd", $event->getData());
68-
}
69-
70-
public function spaceProvider()
71-
{
72-
return array(
73-
// separators
74-
array('0020'),
75-
array('00A0'),
76-
array('1680'),
77-
// array('180E'),
78-
array('2000'),
79-
array('2001'),
80-
array('2002'),
81-
array('2003'),
82-
array('2004'),
83-
array('2005'),
84-
array('2006'),
85-
array('2007'),
86-
array('2008'),
87-
array('2009'),
88-
array('200A'),
89-
array('2028'),
90-
array('2029'),
91-
array('202F'),
92-
array('205F'),
93-
array('3000'),
94-
// controls
95-
array('0009'),
96-
array('000A'),
97-
array('000B'),
98-
array('000C'),
99-
array('000D'),
100-
array('0085'),
101-
// zero width space
102-
// array('200B'),
103-
);
104-
}
10542
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form\Tests\Util;
4+
5+
use Symfony\Component\Form\Util\StringUtil;
6+
7+
class StringUtilTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testTrim()
10+
{
11+
$data = ' Foo! ';
12+
13+
$this->assertEquals('Foo!', StringUtil::trim($data));
14+
}
15+
16+
/**
17+
* @dataProvider spaceProvider
18+
*/
19+
public function testTrimUtf8Separators($hex)
20+
{
21+
if (!function_exists('mb_convert_encoding')) {
22+
$this->markTestSkipped('The "mb_convert_encoding" function is not available');
23+
}
24+
25+
// Convert hexadecimal representation into binary
26+
// H: hex string, high nibble first (UCS-2BE)
27+
// *: repeat until end of string
28+
$binary = pack('H*', $hex);
29+
30+
// Convert UCS-2BE to UTF-8
31+
$symbol = mb_convert_encoding($binary, 'UTF-8', 'UCS-2BE');
32+
$symbol = $symbol."ab\ncd".$symbol;
33+
34+
$this->assertSame("ab\ncd", StringUtil::trim($symbol));
35+
}
36+
37+
public function spaceProvider()
38+
{
39+
return array(
40+
// separators
41+
array('0020'),
42+
array('00A0'),
43+
array('1680'),
44+
// array('180E'),
45+
array('2000'),
46+
array('2001'),
47+
array('2002'),
48+
array('2003'),
49+
array('2004'),
50+
array('2005'),
51+
array('2006'),
52+
array('2007'),
53+
array('2008'),
54+
array('2009'),
55+
array('200A'),
56+
array('2028'),
57+
array('2029'),
58+
array('202F'),
59+
array('205F'),
60+
array('3000'),
61+
// controls
62+
array('0009'),
63+
array('000A'),
64+
array('000B'),
65+
array('000C'),
66+
array('000D'),
67+
array('0085'),
68+
// zero width space
69+
// array('200B'),
70+
);
71+
}
72+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Util;
13+
14+
/**
15+
* @author Issei Murasawa <[email protected]>
16+
* @author Bernhard Schussek <[email protected]>
17+
*/
18+
class StringUtil
19+
{
20+
/**
21+
* This class should not be instantiated.
22+
*/
23+
private function __construct()
24+
{
25+
}
26+
27+
/**
28+
* Returns the trimmed data.
29+
*
30+
* @param string $string
31+
*
32+
* @return string
33+
*/
34+
public static function trim($string)
35+
{
36+
if (null !== $result = @preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $string)) {
37+
return $result;
38+
} else {
39+
return trim($string);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)