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
-------

426fb45cfb [Routing] Disallow object usage inside Route
This commit is contained in:
Nicolas Grekas 2018-06-28 08:30:39 +02:00
commit 9604e69d7c
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