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

Browse filesBrowse files
bug #31207 [Routing] Fixed unexpected 404 NoConfigurationException (yceruto)
This PR was merged into the 4.2 branch. Discussion ---------- [Routing] Fixed unexpected 404 NoConfigurationException | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31199 | License | MIT This is the patch for 4.2+ We need a different patch for 3.4 that is more complex, I think. Commits ------- aa71a42 [Routing] Fixed unexpected 404 NoConfigurationException
2 parents 7de0f01 + aa71a42 commit 77684e4
Copy full SHA for 77684e4

File tree

3 files changed

+16
-27
lines changed
Filter options

3 files changed

+16
-27
lines changed

‎src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherTrait.php
+9-13Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function match($pathinfo)
4242
throw new MethodNotAllowedException(array_keys($allow));
4343
}
4444
if (!$this instanceof RedirectableUrlMatcherInterface) {
45-
throw new ResourceNotFoundException();
45+
throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $pathinfo));
4646
}
4747
if (!\in_array($this->context->getMethod(), ['HEAD', 'GET'], true)) {
4848
// no-op
@@ -67,7 +67,7 @@ public function match($pathinfo)
6767
}
6868
}
6969

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

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

112112
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
113-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
114-
if ($hasRequiredScheme) {
115-
$allow += $requiredMethods;
116-
}
113+
if ($hasRequiredScheme && $requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
114+
$allow += $requiredMethods;
117115
continue;
118116
}
119117

@@ -157,15 +155,13 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
157155
}
158156
}
159157

160-
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
161-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
162-
if ($hasRequiredScheme) {
163-
$allow += $requiredMethods;
164-
}
158+
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
159+
$allowSchemes += $requiredSchemes;
165160
continue;
166161
}
167-
if (!$hasRequiredScheme) {
168-
$allowSchemes += $requiredSchemes;
162+
163+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
164+
$allow += $requiredMethods;
169165
continue;
170166
}
171167

‎src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/UrlMatcher.php
+6-14Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function match($pathinfo)
8989
return $ret;
9090
}
9191

92-
if ('/' === $pathinfo && !$this->allow) {
92+
if ('/' === $pathinfo && !$this->allow && !$this->allowSchemes) {
9393
throw new NoConfigurationException();
9494
}
9595

@@ -182,24 +182,16 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
182182
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
183183
return $this->allow = $this->allowSchemes = [];
184184
}
185-
186185
continue;
187186
}
188187

189-
$hasRequiredScheme = !$route->getSchemes() || $route->hasScheme($this->context->getScheme());
190-
if ($requiredMethods) {
191-
if (!\in_array($method, $requiredMethods)) {
192-
if ($hasRequiredScheme) {
193-
$this->allow = array_merge($this->allow, $requiredMethods);
194-
}
195-
196-
continue;
197-
}
198-
}
199-
200-
if (!$hasRequiredScheme) {
188+
if ($route->getSchemes() && !$route->hasScheme($this->context->getScheme())) {
201189
$this->allowSchemes = array_merge($this->allowSchemes, $route->getSchemes());
190+
continue;
191+
}
202192

193+
if ($requiredMethods && !\in_array($method, $requiredMethods)) {
194+
$this->allow = array_merge($this->allow, $requiredMethods);
203195
continue;
204196
}
205197

‎src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ public function testNestedCollections()
727727

728728
/**
729729
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
730+
* @expectedExceptionMessage No routes found for "/".
730731
*/
731732
public function testSchemeAndMethodMismatch()
732733
{

0 commit comments

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