Skip to content

Commit 9604e69

Browse files
bug symfony#27727 [Routing] Disallow object usage inside Route (paxal)
This PR was submitted for the master branch but it was merged into the 4.1 branch instead (closes symfony#27727). Discussion ---------- [Routing] Disallow object usage inside Route | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | ? | Fixed tickets | symfony#27723 | License | MIT | Doc PR | ✘ As discussed in symfony#27723 the `Route` object should not support nested objects as attributes (`requirements`, `defaults`, ...). Thus, if detected, an `\InvalidArgumentException` will be thrown. Will fix symfony#27723 Commits ------- 426fb45 [Routing] Disallow object usage inside Route
2 parents 3f4644b + 426fb45 commit 9604e69

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Symfony/Component/Routing/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) {

src/Symfony/Component/Routing/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)