Skip to content
Permalink
Browse files

Fix issue #11415

  • Loading branch information...
Joep Roebroek
Joep Roebroek committed Apr 8, 2018
1 parent 30c96dd commit 8a1f369d241655f414aef128bdebeccd7df2a983
Showing with 43 additions and 14 deletions.
  1. +13 −13 src/Routing/Route/Route.php
  2. +30 −1 tests/TestCase/Routing/Route/RouteTest.php
@@ -609,19 +609,6 @@ public function match(array $url, array $context = [])
unset($context['params']);
$hostOptions = array_intersect_key($url, $context);
// Check for properties that will cause an
// absolute url. Copy the other properties over.
if (isset($hostOptions['_scheme']) ||
isset($hostOptions['_port']) ||
isset($hostOptions['_host'])
) {
$hostOptions += $context;
if ($hostOptions['_port'] == $context['_port']) {
unset($hostOptions['_port']);
}
}
// Apply the _host option if possible
if (isset($this->options['_host'])) {
if (!isset($hostOptions['_host']) && strpos($this->options['_host'], '*') === false) {
@@ -637,6 +624,19 @@ public function match(array $url, array $context = [])
}
}
// Check for properties that will cause an
// absolute url. Copy the other properties over.
if (isset($hostOptions['_scheme']) ||
isset($hostOptions['_port']) ||
isset($hostOptions['_host'])
) {
$hostOptions += $context;
if (getservbyname($hostOptions['_scheme'], 'tcp') === $hostOptions['_port']) {
unset($hostOptions['_port']);
}
}
// If no base is set, copy one in.
if (!isset($hostOptions['_base']) && isset($context['_base'])) {
$hostOptions['_base'] = $context['_base'];
@@ -570,7 +570,7 @@ public function testMatchWithHostKeys()
['controller' => 'posts', 'action' => 'index', '_scheme' => 'webcal'],
$context
);
$this->assertEquals('webcal://foo.com/posts/index', $result);
$this->assertEquals('webcal://foo.com:80/posts/index', $result);
$result = $route->match(
['controller' => 'posts', 'action' => 'index', '_port' => '8080'],
@@ -596,6 +596,25 @@ public function testMatchWithHostKeys()
$context
);
$this->assertEquals('https://example.com:8080/dir/posts/index', $result);
$context = [
'_host' => 'foo.com',
'_scheme' => 'http',
'_port' => 8080,
'_base' => ''
];
$result = $route->match(
[
'controller' => 'posts',
'action' => 'index',
'_port' => '8080',
'_host' => 'example.com',
'_scheme' => 'https',
'_base' => '/dir'
],
$context
);
$this->assertEquals('https://example.com:8080/dir/posts/index', $result);
}
/**
@@ -662,6 +681,16 @@ public function testMatchWithHostWildcardOption()
'_host' => 'foo.example.com'
]);
$this->assertSame('http://foo.example.com/fallback', $result);
$result = $route->match([
'controller' => 'Articles',
'action' => 'index',
], [
'_scheme' => 'https',
'_host' => 'foo.example.com',
'_port' => 8080
]);
$this->assertSame('https://foo.example.com:8080/fallback', $result);
}
/**

0 comments on commit 8a1f369

Please sign in to comment.
You can’t perform that action at this time.