Skip to content

Commit 4c483ba

Browse files
bug symfony#23457 [FrameworkBundle] check _controller attribute is a string before parsing it (alekitto)
This PR was merged into the 3.3 branch. Discussion ---------- [FrameworkBundle] check _controller attribute is a string before parsing it | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#23456 | License | MIT Avoids an error to be raised in case described in issue symfony#23456. Commits ------- 0b349ae check _controller attribute is a string before parsing it
2 parents c3ec5c5 + 0b349ae commit 4c483ba

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/EventListener/ResolveControllerNameSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(ControllerNameParser $parser)
3333
public function onKernelRequest(GetResponseEvent $event)
3434
{
3535
$controller = $event->getRequest()->attributes->get('_controller');
36-
if ($controller && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
36+
if (is_string($controller) && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
3737
// controller in the a:b:c notation then
3838
$event->getRequest()->attributes->set('_controller', $this->parser->parse($controller));
3939
}

src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,27 @@ public function testReplacesControllerAttribute()
3737
$this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller'));
3838
}
3939

40-
public function testSkipsOtherControllerFormats()
40+
/**
41+
* @dataProvider provideSkippedControllers
42+
*/
43+
public function testSkipsOtherControllerFormats($controller)
4144
{
4245
$parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
4346
$parser->expects($this->never())
4447
->method('parse');
4548
$httpKernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
4649

4750
$request = new Request();
48-
$request->attributes->set('_controller', 'Other:format');
51+
$request->attributes->set('_controller', $controller);
4952

5053
$subscriber = new ResolveControllerNameSubscriber($parser);
5154
$subscriber->onKernelRequest(new GetResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
52-
$this->assertEquals('Other:format', $request->attributes->get('_controller'));
55+
$this->assertEquals($controller, $request->attributes->get('_controller'));
56+
}
57+
58+
public function provideSkippedControllers()
59+
{
60+
yield array('Other:format');
61+
yield array(function () {});
5362
}
5463
}

0 commit comments

Comments
 (0)