Skip to content

Commit 8e248f3

Browse files
committed
fix: limit to subdomain '*' does not work
1 parent 585d3ca commit 8e248f3

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

system/Router/RouteCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ private function getMethodParams(string $from): string
12971297
* Compares the subdomain(s) passed in against the current subdomain
12981298
* on this page request.
12991299
*
1300-
* @param mixed $subdomains
1300+
* @param string|string[] $subdomains
13011301
*/
13021302
private function checkSubdomains($subdomains): bool
13031303
{
@@ -1330,7 +1330,7 @@ private function checkSubdomains($subdomains): bool
13301330
* It's especially not perfect since it's possible to register a domain
13311331
* with a period (.) as part of the domain name.
13321332
*
1333-
* @return mixed
1333+
* @return false|string the subdomain
13341334
*/
13351335
private function determineCurrentSubdomain()
13361336
{
@@ -1351,7 +1351,7 @@ private function determineCurrentSubdomain()
13511351
}
13521352

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

13561356
// Account for .co.uk, .co.nz, etc. domains
13571357
if (end($host) === 'co') {

tests/system/Router/RouteCollectionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,20 @@ public function testWithDifferentSubdomainMissing()
11561156
$this->assertSame($expects, $routes->getRoutes());
11571157
}
11581158

1159+
/**
1160+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5959
1161+
*/
1162+
public function testWithNoSubdomainAndDot()
1163+
{
1164+
$_SERVER['HTTP_HOST'] = 'example.com';
1165+
1166+
$routes = $this->getCollector();
1167+
1168+
$routes->add('/objects/(:alphanum)', 'App::objectsList/$1', ['subdomain' => '*']);
1169+
1170+
$this->assertSame([], $routes->getRoutes());
1171+
}
1172+
11591173
/**
11601174
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1692
11611175
*/

0 commit comments

Comments
 (0)