Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 62e7de8

Browse filesBrowse files
committed
Make sure the controller & redirect_to configurations conflict with a correct error message
1 parent 3c4ccbe commit 62e7de8
Copy full SHA for 62e7de8

File tree

6 files changed

+40
-0
lines changed
Filter options

6 files changed

+40
-0
lines changed

‎src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/XmlFileLoader.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ private function parseConfigs(\DOMElement $node, $path)
244244
}
245245

246246
if ($redirectTo = $node->getAttribute('redirect-to')) {
247+
if (isset($defaults['_controller'])) {
248+
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both a controller and a redirection.', $path));
249+
}
250+
247251
$defaults['_redirect_to'] = $redirectTo;
248252
$defaults['_redirect_permanent'] = (bool) $node->getAttribute('redirect-permanent');
249253
}

‎src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/YamlFileLoader.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ protected function parseRoute(RouteCollection $collection, $name, array $config,
120120
}
121121

122122
if (isset($config['redirect_to'])) {
123+
if (isset($defaults['_controller'])) {
124+
throw new \InvalidArgumentException(sprintf('The routing file "%s" must not specify both a controller and a redirection.', $path));
125+
}
126+
123127
$defaults['_redirect_to'] = $config['redirect_to'];
124128
$defaults['_redirect_permanent'] = $config['redirect_permanent'] ?? false;
125129
}
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing
5+
http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="app_symfony" path="/symfony" redirect-to="https://symfony.com" controller="App\Controller\Symfony" />
8+
</routes>
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
app_symfony:
2+
path: /symfony
3+
controller: App\Controller\Symfony
4+
redirect_to: https://symfony.com

‎src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,14 @@ public function testRedirections()
389389
$this->assertSame('/', $route->getDefault('_redirect_to'));
390390
$this->assertTrue($route->getDefault('_redirect_permanent'));
391391
}
392+
393+
/**
394+
* @expectedException \InvalidArgumentException
395+
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both a controller and a redirection./
396+
*/
397+
public function testRedirectionCannotBeUsedWithController()
398+
{
399+
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/redirect_to')));
400+
$loader->load('redirect_with_controller.xml');
401+
}
392402
}

‎src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,14 @@ public function testRedirections()
210210
$this->assertSame('/', $route->getDefault('_redirect_to'));
211211
$this->assertTrue($route->getDefault('_redirect_permanent'));
212212
}
213+
214+
/**
215+
* @expectedException \InvalidArgumentException
216+
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both a controller and a redirection./
217+
*/
218+
public function testRedirectionCannotBeUsedWithController()
219+
{
220+
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/redirect_to')));
221+
$loader->load('redirect_with_controller.yml');
222+
}
213223
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.