Permalink
Browse files

bug #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 | #23456
| License       | MIT

Avoids an error to be raised in case described in issue #23456.

Commits
-------

0b349ae check _controller attribute is a string before parsing it
  • Loading branch information...
nicolas-grekas committed Jul 11, 2017
2 parents c3ec5c5 + 0b349ae commit 4c483ba3f4049b54ae97dffe922d82592efe7794
@@ -33,7 +33,7 @@ public function __construct(ControllerNameParser $parser)
public function onKernelRequest(GetResponseEvent $event)
{
$controller = $event->getRequest()->attributes->get('_controller');
if ($controller && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
if (is_string($controller) && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
// controller in the a:b:c notation then
$event->getRequest()->attributes->set('_controller', $this->parser->parse($controller));
}
@@ -37,18 +37,27 @@ public function testReplacesControllerAttribute()
$this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller'));
}
public function testSkipsOtherControllerFormats()
/**
* @dataProvider provideSkippedControllers
*/
public function testSkipsOtherControllerFormats($controller)
{
$parser = $this->getMockBuilder(ControllerNameParser::class)->disableOriginalConstructor()->getMock();
$parser->expects($this->never())
->method('parse');
$httpKernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = new Request();
$request->attributes->set('_controller', 'Other:format');
$request->attributes->set('_controller', $controller);
$subscriber = new ResolveControllerNameSubscriber($parser);
$subscriber->onKernelRequest(new GetResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST));
$this->assertEquals('Other:format', $request->attributes->get('_controller'));
$this->assertEquals($controller, $request->attributes->get('_controller'));
}
public function provideSkippedControllers()
{
yield array('Other:format');
yield array(function () {});
}
}

0 comments on commit 4c483ba

Please sign in to comment.