Skip to content

Commit c97abe7

Browse files
Merge branch '6.4' into 7.3
* 6.4: [HttpClient] Reject 3xx pushed responses [ProxyManagerBridge] Remove comment that reference github discussion [Routing] Fix matching the "0" URL The BrowserKit history with parameter separator without slash.
2 parents 8dc648e + ae064a6 commit c97abe7

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

Matcher/Dumper/CompiledUrlMatcherTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function match(string $pathinfo): array
5757
} finally {
5858
$this->context->setScheme($scheme);
5959
}
60-
} elseif ('/' !== $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
60+
} elseif ('' !== $trimmedPathinfo = rtrim($pathinfo, '/')) {
6161
$pathinfo = $trimmedPathinfo === $pathinfo ? $pathinfo.'/' : $trimmedPathinfo;
6262
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
6363
return $this->redirect($pathinfo, $ret['_route']) + $ret;
@@ -73,8 +73,8 @@ public function match(string $pathinfo): array
7373
private function doMatch(string $pathinfo, array &$allow = [], array &$allowSchemes = []): array
7474
{
7575
$allow = $allowSchemes = [];
76-
$pathinfo = rawurldecode($pathinfo) ?: '/';
77-
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
76+
$pathinfo = '' === ($pathinfo = rawurldecode($pathinfo)) ? '/' : $pathinfo;
77+
$trimmedPathinfo = '' === ($trimmedPathinfo = rtrim($pathinfo, '/')) ? '/' : $trimmedPathinfo;
7878
$context = $this->context;
7979
$requestMethod = $canonicalMethod = $context->getMethod();
8080

Matcher/RedirectableUrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function match(string $pathinfo): array
4141
} finally {
4242
$this->context->setScheme($scheme);
4343
}
44-
} elseif ('/' === $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/') {
44+
} elseif ('' === $trimmedPathinfo = rtrim($pathinfo, '/')) {
4545
throw $e;
4646
} else {
4747
try {

Matcher/TraceableUrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a
5757
$method = 'GET';
5858
}
5959
$supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
60-
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
60+
$trimmedPathinfo = '' === ($trimmedPathinfo = rtrim($pathinfo, '/')) ? '/' : $trimmedPathinfo;
6161

6262
foreach ($routes as $name => $route) {
6363
$compiledRoute = $route->compile();

Matcher/UrlMatcher.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public function getContext(): RequestContext
7070
public function match(string $pathinfo): array
7171
{
7272
$this->allow = $this->allowSchemes = [];
73+
$pathinfo = '' === ($pathinfo = rawurldecode($pathinfo)) ? '/' : $pathinfo;
7374

74-
if ($ret = $this->matchCollection(rawurldecode($pathinfo) ?: '/', $this->routes)) {
75+
if ($ret = $this->matchCollection($pathinfo, $this->routes)) {
7576
return $ret;
7677
}
7778

@@ -114,7 +115,7 @@ protected function matchCollection(string $pathinfo, RouteCollection $routes): a
114115
$method = 'GET';
115116
}
116117
$supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
117-
$trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';
118+
$trimmedPathinfo = '' === ($trimmedPathinfo = rtrim($pathinfo, '/')) ? '/' : $trimmedPathinfo;
118119

119120
foreach ($routes as $name => $route) {
120121
$compiledRoute = $route->compile();

Tests/Matcher/UrlMatcherTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
class UrlMatcherTest extends TestCase
2424
{
25+
public function testZero()
26+
{
27+
$coll = new RouteCollection();
28+
$coll->add('index', new Route('/'));
29+
30+
$matcher = $this->getUrlMatcher($coll);
31+
32+
$this->expectException(ResourceNotFoundException::class);
33+
$matcher->match('0');
34+
}
35+
2536
public function testNoMethodSoAllowed()
2637
{
2738
$coll = new RouteCollection();

0 commit comments

Comments
 (0)