Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5355629

Browse filesBrowse files
committed
bug #31421 [Routing][AnnotationClassLoader] fix utf-8 encoding in default route name (przemyslaw-bogusz)
This PR was squashed before being merged into the 3.4 branch (closes #31421). Discussion ---------- [Routing][AnnotationClassLoader] fix utf-8 encoding in default route name | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT If controller, or one of its methods, contain a unicode character and you run: ``` ./bin/console debug:router ``` you get this: ![Zrzut ekranu 2019-05-8 o 14 00 48](https://user-images.githubusercontent.com/35422131/57374545-71863080-719b-11e9-999e-fe0a5051c089.png) This PR fixes it into this: ![Zrzut ekranu 2019-05-8 o 14 00 59](https://user-images.githubusercontent.com/35422131/57374616-92e71c80-719b-11e9-9d13-5370213c22f7.png) Commits ------- 7ab52d3 [Routing][AnnotationClassLoader] fix utf-8 encoding in default route name
2 parents c866efa + 7ab52d3 commit 5355629
Copy full SHA for 5355629

File tree

4 files changed

+35
-2
lines changed
Filter options

4 files changed

+35
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
+2-1Lines 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
}
+10Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php
+21Lines 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+
$this->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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
+2-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.