Skip to content

Commit fb67e65

Browse files
committed
Merge pull request #1999 from ossinkine/canonicalizer-fix
Fix Canonicalizer with illegal chars
2 parents a315355 + 00cf383 commit fb67e65

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Tests/Util/CanonicalizerTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\UserBundle\Tests\Util;
13+
14+
use FOS\UserBundle\Util\Canonicalizer;
15+
16+
class CanonicalizerTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider canonicalizeProvider
20+
*/
21+
public function testCanonicalize($source, $expectedResult)
22+
{
23+
$canonicalizer = new Canonicalizer();
24+
$this->assertEquals($expectedResult, $canonicalizer->canonicalize($source));
25+
}
26+
27+
public function canonicalizeProvider()
28+
{
29+
return array(
30+
array('FOO', 'foo'),
31+
array(chr(171), PHP_VERSION_ID < 50600 ? chr(171) : '?'),
32+
);
33+
}
34+
}

Util/Canonicalizer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313

1414
class Canonicalizer implements CanonicalizerInterface
1515
{
16+
/**
17+
* {@inheritdoc}
18+
*/
1619
public function canonicalize($string)
1720
{
18-
return mb_convert_case($string, MB_CASE_LOWER, mb_detect_encoding($string));
21+
$encoding = mb_detect_encoding($string);
22+
$result = $encoding
23+
? mb_convert_case($string, MB_CASE_LOWER, $encoding)
24+
: mb_convert_case($string, MB_CASE_LOWER);
25+
26+
return $result;
1927
}
2028
}

0 commit comments

Comments
 (0)