Skip to content

Commit

Permalink
[Routing][AnnotationClassLoader] fix utf-8 encoding in default route …
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
przemyslaw-bogusz authored and fabpot committed May 18, 2019
1 parent 75d1dd4 commit 7ab52d3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Expand Up @@ -199,7 +199,8 @@ public function getResolver()
*/
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
$name = strtolower(str_replace('\\', '_', $class->name).'_'.$method->name);
$name = str_replace('\\', '_', $class->name).'_'.$method->name;
$name = \function_exists('mb_strtolower') && preg_match('//u', $name) ? mb_strtolower($name, 'UTF-8') : strtolower($name);
if ($this->defaultRouteIndex > 0) {
$name .= '_'.$this->defaultRouteIndex;
}
Expand Down
@@ -0,0 +1,10 @@
<?php

namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;

class EncodingClass
{
public function routeÀction()
{
}
}
Expand Up @@ -324,6 +324,27 @@ public function testInvokableClassWithMethodRouteLoad()
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
}

/**
* @requires function mb_strtolower
*/
public function testDefaultRouteName()
{
$methodRouteData = [
'name' => null,
];

$this->reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue([$this->getAnnotatedRoute($methodRouteData)]))
;

$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\EncodingClass');
$defaultName = array_keys($routeCollection->all())[0];

$this->assertSame($defaultName, 'symfony_component_routing_tests_fixtures_annotatedclasses_encodingclass_routeàction');
}

private function getAnnotatedRoute($data)
{
return new Route($data);
Expand Down
Expand Up @@ -29,7 +29,7 @@ protected function setUp()

public function testLoad()
{
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
$this->reader->expects($this->exactly(4))->method('getClassAnnotation');

$this->reader
->expects($this->any())
Expand All @@ -52,6 +52,7 @@ public function testLoadIgnoresHiddenDirectories()
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\EncodingClass',
]);

$this->reader
Expand Down

0 comments on commit 7ab52d3

Please sign in to comment.