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

[Routing] Fixed unexpected 404 NoConfigurationException #31207

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
May 9, 2019
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
22 changes: 9 additions & 13 deletions 22 src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function match($pathinfo)
throw new MethodNotAllowedException(array_keys($allow));
}
if (!$this instanceof RedirectableUrlMatcherInterface) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
}
if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) {
// no-op
Expand All @@ -67,7 +67,7 @@ public function match($pathinfo)
}
}

throw new ResourceNotFoundException();
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
}

private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []): array
Expand Down Expand Up @@ -110,10 +110,8 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
}

$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
if ($hasRequiredScheme && $requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
continue;
}

Expand Down Expand Up @@ -157,15 +155,13 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
}
}

$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
if ($hasRequiredScheme) {
$allow += $requiredMethods;
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$allowSchemes += $requiredSchemes;
continue;
}
if (!$hasRequiredScheme) {
$allowSchemes += $requiredSchemes;

if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
$allow += $requiredMethods;
continue;
}

Expand Down
20 changes: 6 additions & 14 deletions 20 src/Symfony/Component/Routing/Matcher/UrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function match($pathinfo)
return $ret;
}

if ('/' === $pathinfo && !$this->allow) {
if ('/' === $pathinfo && !$this->allow && !$this->allowSchemes) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to what we have in PhpMatcherTrait:

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

throw new NoConfigurationException();
}

Expand Down Expand Up @@ -182,24 +182,16 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
return $this->allow = $this->allowSchemes = [];
}

continue;
}

$hasRequiredScheme = !$route->getSchemes() || $route->hasScheme($this->context->getScheme());
if ($requiredMethods) {
if (!\in_array($method, $requiredMethods)) {
if ($hasRequiredScheme) {
$this->allow = array_merge($this->allow, $requiredMethods);
}

continue;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this continue outside the if ($hasRequiredScheme) was preventing to collect the $this->allowSchemes bellow

}
}

if (!$hasRequiredScheme) {
if ($route->getSchemes() && !$route->hasScheme($this->context->getScheme())) {
$this->allowSchemes = array_merge($this->allowSchemes, $route->getSchemes());
continue;
}

if ($requiredMethods && !\in_array($method, $requiredMethods)) {
$this->allow = array_merge($this->allow, $requiredMethods);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ public function testNestedCollections()

/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
* @expectedExceptionMessage No routes found for "/".
Copy link
Member Author

@yceruto yceruto Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making sure it is a ResourceNotFoundException and not a NoConfigurationException which has no message.

*/
public function testSchemeAndMethodMismatch()
{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.