Skip to content

Commit 73770bf

Browse files
paxalnicolas-grekas
authored andcommitted
[Routing] Disallow object usage inside Route
1 parent 6cf7a0c commit 73770bf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ public static function export($value): string
746746
return 'null';
747747
}
748748
if (!\is_array($value)) {
749+
if (\is_object($value)) {
750+
throw new \InvalidArgumentException('Symfony\Component\Routing\Route cannot contain objects.');
751+
}
752+
749753
return str_replace("\n", '\'."\n".\'', var_export($value, true));
750754
}
751755
if (!$value) {

Tests/Matcher/Dumper/PhpMatcherDumperTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,18 @@ private function generateDumpedMatcher(RouteCollection $collection, $redirectabl
491491

492492
return $this->matcherClass;
493493
}
494+
495+
/**
496+
* @expectedException \InvalidArgumentException
497+
* @expectedExceptionMessage Symfony\Component\Routing\Route cannot contain objects
498+
*/
499+
public function testGenerateDumperMatcherWithObject()
500+
{
501+
$routeCollection = new RouteCollection();
502+
$routeCollection->add('_', new Route('/', array(new \stdClass())));
503+
$dumper = new PhpMatcherDumper($routeCollection);
504+
$dumper->dump();
505+
}
494506
}
495507

496508
abstract class RedirectableUrlMatcherStub extends UrlMatcher implements RedirectableUrlMatcherInterface

0 commit comments

Comments
 (0)