diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php index 374d0eba10..989dc8cd23 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php @@ -46,11 +46,12 @@ class ControllerNameParser */ public function parse($controller) { - $originalController = $controller; - if (3 !== count($parts = explode(':', $controller))) { + $parts = explode(':', $controller); + if (3 !== count($parts) || in_array('', $parts, true)) { throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller)); } + $originalController = $controller; list($bundle, $controller, $action) = $parts; $controller = str_replace('/', '\\', $controller); $bundles = array(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php index 801149372a..29f3072a89 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php @@ -21,7 +21,7 @@ use Psr\Log\LoggerInterface; * DelegatingLoader delegates route loading to other loaders using a loader resolver. * * This implementation resolves the _controller attribute from the short notation - * to the fully-qualified form (from a:b:c to class:method). + * to the fully-qualified form (from a:b:c to class::method). * * @author Fabien Potencier */ @@ -85,15 +85,17 @@ class DelegatingLoader extends BaseDelegatingLoader $this->loading = false; foreach ($collection->all() as $route) { - if ($controller = $route->getDefault('_controller')) { - try { - $controller = $this->parser->parse($controller); - } catch (\InvalidArgumentException $e) { - // unable to optimize unknown notation - } - - $route->setDefault('_controller', $controller); + if (!$controller = $route->getDefault('_controller')) { + continue; } + + try { + $controller = $this->parser->parse($controller); + } catch (\InvalidArgumentException $e) { + // unable to optimize unknown notation + } + + $route->setDefault('_controller', $controller); } return $collection;