8000 [Routing] Fix throwing NoConfigurationException instead of 405 by nicolas-grekas · Pull Request #26792 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] Fix throwing NoConfigurationException instead of 405 #26792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Routing] Fix throwing NoConfigurationException instead of 405
  • Loading branch information
nicolas-grekas committed Apr 4, 2018
commit 73269cfd0ebc61dfa49b1c8654bfa270f29766bb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections)
}

// 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";

Expand Down Expand Up @@ -362,7 +362,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
EOF;
}
} elseif ($methods) {
$code .= <<<EOF
$code .= <<<EOF
if (!in_array($methodVariable, array('$methods'))) {
\$allow = array_merge(\$allow, array('$methods'));
goto $gotoname;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Matcher/UrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function match($pathinfo)
return $ret;
}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$this->allow) {
throw new NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function match($rawPathinfo)
$canonicalMethod = 'GET';
}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function match($rawPathinfo)

}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public function match($rawPathinfo)
}
not_nonsecure:

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function match($rawPathinfo)
return array('_route' => 'with-condition');
}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function match($rawPathinfo)

}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function match($rawPathinfo)

}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function match($rawPathinfo)

}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function match($rawPathinfo)

}

if ('/' === $pathinfo) {
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}

Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ public function testMethodNotAllowed()
}
}

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();
Expand Down
0