[Routing] Fix throwing NoConfigurationException instead of 405

This commit is contained in:
Nicolas Grekas 2018-04-04 15:19:51 +02:00
parent 946eefa284
commit 73269cfd0e
11 changed files with 26 additions and 11 deletions

View File

@ -154,7 +154,7 @@ EOF;
}
// used to display the Welcome Page in apps that don't define a homepage
$code .= " if ('/' === \$pathinfo) {\n";
$code .= " if ('/' === \$pathinfo && !\$allow) {\n";
$code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n";
$code .= " }\n";
@ -362,7 +362,7 @@ EOF;
EOF;
}
} elseif ($methods) {
$code .= <<<EOF
$code .= <<<EOF
if (!in_array($methodVariable, array('$methods'))) {
\$allow = array_merge(\$allow, array('$methods'));
goto $gotoname;

View File

@ -76,7 +76,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
return $ret;
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$this->allow) {
throw new NoConfigurationException();
}

View File

@ -28,7 +28,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
$canonicalMethod = 'GET';
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -309,7 +309,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -371,7 +371,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
not_nonsecure:
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -46,7 +46,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
return array('_route' => 'with-condition');
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -103,7 +103,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -200,7 +200,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -204,7 +204,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -240,7 +240,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

View File

@ -45,6 +45,21 @@ class UrlMatcherTest extends TestCase
}
}
public function testMethodNotAllowedOnRoot()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), '', array(), array('GET')));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
try {
$matcher->match('/');
$this->fail();
} catch (MethodNotAllowedException $e) {
$this->assertEquals(array('GET'), $e->getAllowedMethods());
}
}
public function testHeadAllowedWhenRequirementContainsGet()
{
$coll = new RouteCollection();