Skip to content

Commit 8e6763a

Browse files
committed
[Form] Don't trim unassigned unicode characters anymore
1 parent 0d35d24 commit 8e6763a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Symfony/Component/Form/Tests/Util/StringUtilTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@
1616

1717
class StringUtilTest extends TestCase
1818
{
19-
public function testTrim()
19+
public function trimProvider()
2020
{
21-
$data = ' Foo! ';
21+
return [
22+
[' Foo! ', 'Foo!'],
23+
["\u{1F92E}", "\u{1F92E}"], // unassigned character in PCRE versions of <PHP 7.3
24+
];
25+
}
2226

23-
$this->assertEquals('Foo!', StringUtil::trim($data));
27+
/**
28+
* @dataProvider trimProvider
29+
*/
30+
public function testTrim($data, $expectedData)
31+
{
32+
$this->assertSame($expectedData, StringUtil::trim($data));
2433
}
2534

2635
/**

src/Symfony/Component/Form/Util/StringUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private function __construct()
3333
*/
3434
public static function trim($string)
3535
{
36-
if (null !== $result = @preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $string)) {
36+
if (null !== $result = @preg_replace('/^[\pZ\p{Cc}\p{Cf}]+|[\pZ\p{Cc}\p{Cf}]+$/u', '', $string)) {
3737
return $result;
3838
}
3939

0 commit comments

Comments
 (0)