Permalink
Browse files

bug #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 #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 | #27723
| License       | MIT
| Doc PR        | ✘

As discussed in #27723 the `Route` object should not support nested objects as attributes (`requirements`, `defaults`, ...).

Thus, if detected, an `\InvalidArgumentException` will be thrown.

Will fix #27723

Commits
-------

426fb45 [Routing] Disallow object usage inside Route
  • Loading branch information...
nicolas-grekas committed Jun 28, 2018
2 parents 3f4644b + 426fb45 commit 9604e69d7c41da8af82297dee680ded98090c8a8
@@ -746,6 +746,10 @@ public static function export($value): string
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) {
@@ -491,6 +491,18 @@ private function generateDumpedMatcher(RouteCollection $collection, $redirectabl
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

0 comments on commit 9604e69

Please sign in to comment.