8000 [Routing][AnnotationClassLoader] fix utf-8 encoding in default route … · symfony/symfony@7ab52d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ab52d3

Browse files
przemyslaw-boguszfabpot
authored andcommitted
[Routing][AnnotationClassLoader] fix utf-8 encoding in default route name
1 parent 75d1dd4 commit 7ab52d3

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public function getResolver()
199199
*/
200200
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
201201
{
202-
$name = strtolower(str_replace('\\', '_', $class->name).'_'.$method->name);
202+
$name = str_replace('\\', '_', $class->name).'_'.$method->name;
203+
$name = \function_exists('mb_strtolower') && preg_match('//u', $name) ? mb_strtolower($name, 'UTF-8') : strtolower($name);
203204
if ($this->defaultRouteIndex > 0) {
204205
$name .= '_'.$this->defaultRouteIndex;
205206
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
4+
5+
class EncodingClass
6+
{
7+
public function routeÀction()
8+
{
9+
}
10+
}

src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,27 @@ public function testInvokableClassWithMethodRouteLoad()
324324
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
325325
}
326326

327+
/**
328+
* @requires function mb_strtolower
329+
*/
330+
public function testDefaultRouteName()
331+
{
332+
$methodRouteData = [
333+
'name' => null,
334+
];
335+
336+
$t 106F3 his->reader
337+
->expects($this->once())
338+
->method('getMethodAnnotations')
339+
->will($this->returnValue([$this->getAnnotatedRoute($methodRouteData)]))
340+
;
341+
342+
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\EncodingClass');
343+
$defaultName = array_keys($routeCollection->all())[0];
344+
345+
$this->assertSame($defaultName, 'symfony_component_routing_tests_fixtures_annotatedclasses_encodingclass_routeàction');
346+
}
347+
327348
private function getAnnotatedRoute($data)
328349
{
329350
return new Route($data);

src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp()
2929

3030
public function testLoad()
3131
{
32-
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
32+
$this->reader->expects($this->exactly(4))->method('getClassAnnotation');
3333

3434
$this->reader
3535
->expects($this->any())
@@ -52,6 +52,7 @@ public function testLoadIgnoresHiddenDirectories()
5252
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
5353
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
5454
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
55+
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\EncodingClass',
5556
]);
5657

5758
$this->reader

0 commit comments

Comments
 (0)
0