FIX Ignore ports when matching domain for subsite

This commit is contained in:
Robbie Averill 2018-10-19 20:51:43 +02:00
parent 9199d509d6
commit ff9997e0f2
2 changed files with 20 additions and 0 deletions

View File

@ -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) {

View File

@ -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'),