diff --git a/src/Model/Subsite.php b/src/Model/Subsite.php index 229604d..80b7645 100644 --- a/src/Model/Subsite.php +++ b/src/Model/Subsite.php @@ -257,6 +257,10 @@ class Subsite extends DataObject $host = $_SERVER['HTTP_HOST']; } + // Remove ports, we aren't concerned with them in terms of detecting subsites via domains + $hostParts = explode(':', $host); + $host = reset($hostParts); + $matchingDomains = null; $cacheKey = null; if ($host) { diff --git a/tests/php/SubsiteTest.php b/tests/php/SubsiteTest.php index 8e360cb..b3a6a3c 100644 --- a/tests/php/SubsiteTest.php +++ b/tests/php/SubsiteTest.php @@ -191,12 +191,23 @@ class SubsiteTest extends BaseSubsiteTest Subsite::getSubsiteIDForDomain('example.org'), 'Exact matches without strict checking when not using www prefix' ); + $this->assertEquals( + $subsite1->ID, + Subsite::getSubsiteIDForDomain('example.org:1123'), + 'Exact matches without strict checking when not using www prefix and ignores port' + ); $this->assertEquals( $subsite1->ID, Subsite::getSubsiteIDForDomain('www.example.org'), 'Matches without strict checking when using www prefix, ' .'still matching first domain regardless of www prefix (falling back to subsite primary key ordering)' ); + $this->assertEquals( + $subsite1->ID, + Subsite::getSubsiteIDForDomain('www.example.org:9923'), + 'Matches without strict checking when using www prefix, ' + .'still matching first domain without prefix (falling back to primary key ordering and ignoring port)' + ); $this->assertEquals( $subsite1->ID, Subsite::getSubsiteIDForDomain('www.example.com'), @@ -215,6 +226,11 @@ class SubsiteTest extends BaseSubsiteTest Subsite::getSubsiteIDForDomain('example.org'), 'Matches with strict checking when not using www prefix' ); + $this->assertEquals( + $subsite1->ID, + Subsite::getSubsiteIDForDomain('example.org:123'), + 'Matches with strict checking when not using www prefix and ignores port' + ); $this->assertEquals( $subsite2->ID, // not 1 Subsite::getSubsiteIDForDomain('www.example.org'),