[Routing] Disallow object usage inside Route

This commit is contained in:
Cyril PASCAL 2018-06-26 13:02:12 +02:00 committed by Nicolas Grekas
parent 3f4644b2f1
commit 426fb45cfb
2 changed files with 16 additions and 0 deletions

View File

@ -746,6 +746,10 @@ EOF;
return 'null';
}
if (!\is_array($value)) {
if (\is_object($value)) {
throw new \InvalidArgumentException('Symfony\Component\Routing\Route cannot contain objects.');
}
return str_replace("\n", '\'."\n".\'', var_export($value, true));
}
if (!$value) {

View File

@ -491,6 +491,18 @@ class PhpMatcherDumperTest extends TestCase
return $this->matcherClass;
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Symfony\Component\Routing\Route cannot contain objects
*/
public function testGenerateDumperMatcherWithObject()
{
$routeCollection = new RouteCollection();
$routeCollection->add('_', new Route('/', array(new \stdClass())));
$dumper = new PhpMatcherDumper($routeCollection);
$dumper->dump();
}
}
abstract class RedirectableUrlMatcherStub extends UrlMatcher implements RedirectableUrlMatcherInterface