Skip to content
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

fix: route limit to subdomains does not work #5961

Merged
merged 3 commits into from May 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/Router/RouteCollection.php
Expand Up @@ -1297,7 +1297,7 @@ private function getMethodParams(string $from): string
* Compares the subdomain(s) passed in against the current subdomain
* on this page request.
*
* @param mixed $subdomains
* @param string|string[] $subdomains
*/
private function checkSubdomains($subdomains): bool
{
Expand Down Expand Up @@ -1330,7 +1330,7 @@ private function checkSubdomains($subdomains): bool
* It's especially not perfect since it's possible to register a domain
* with a period (.) as part of the domain name.
*
* @return mixed
* @return false|string the subdomain
*/
private function determineCurrentSubdomain()
{
Expand All @@ -1351,7 +1351,7 @@ private function determineCurrentSubdomain()
}

// Get rid of any domains, which will be the last
unset($host[count($host)]);
unset($host[count($host) - 1]);

// Account for .co.uk, .co.nz, etc. domains
if (end($host) === 'co') {
Expand Down
18 changes: 16 additions & 2 deletions tests/system/Router/RouteCollectionTest.php
Expand Up @@ -1128,7 +1128,7 @@ public function testWithDotCoSubdomain()
{
$routes = $this->getCollector();

$_SERVER['HTTP_HOST'] = 'example.uk.co';
$_SERVER['HTTP_HOST'] = 'example.co.uk';

$routes->add('/objects/(:alphanum)', 'Admin::objectsList/$1', ['subdomain' => 'sales']);
$routes->add('/objects/(:alphanum)', 'App::objectsList/$1');
Expand Down Expand Up @@ -1156,6 +1156,20 @@ public function testWithDifferentSubdomainMissing()
$this->assertSame($expects, $routes->getRoutes());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5959
*/
public function testWithNoSubdomainAndDot()
{
$_SERVER['HTTP_HOST'] = 'example.com';

$routes = $this->getCollector();

$routes->add('/objects/(:alphanum)', 'App::objectsList/$1', ['subdomain' => '*']);

$this->assertSame([], $routes->getRoutes());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1692
*/
Expand Down Expand Up @@ -1448,7 +1462,7 @@ public function testRouteToWithGenericSubdomainNot()

$routes->get('i/(:any)', 'App\Controllers\Site\CDoc::item/$1', ['subdomain' => '*', 'as' => 'doc_item']);

$this->assertSame('/i/sth', $routes->reverseRoute('doc_item', 'sth'));
$this->assertFalse($routes->reverseRoute('doc_item', 'sth'));
}

public function testRouteToWithoutSubdomainMatch()
Expand Down