Skip to content

Commit d759574

Browse files
committed
fixed *.org.uk domains #150
1 parent 3b88c2b commit d759574

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Url.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ public function getDomain($first_level = false)
181181
return $first_level ? ($host[1].'.'.$host[0]) : $host[1];
182182

183183
default:
184+
$subdomains = ['co', 'com', 'org'];
185+
184186
if ($first_level) {
185-
return ($host[1] === 'co' || $host[1] === 'com') ? ($host[2].'.'.$host[1].'.'.$host[0]) : ($host[1].'.'.$host[0]);
187+
return in_array($host[1], $subdomains, true) ? ($host[2].'.'.$host[1].'.'.$host[0]) : ($host[1].'.'.$host[0]);
186188
}
187189

188-
return ($host[1] === 'co' || $host[1] === 'com') ? $host[2] : $host[1];
190+
return in_array($host[1], $subdomains, true) ? $host[2] : $host[1];
189191
}
190192
}
191193

tests/UrlTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function urlsParserProvider()
1818
['http://test.drupal.dd:8083/tests/localport.html', 'http://test.drupal.dd:8083/tests/localport.html'],
1919
['http://[email protected]:8083/tests/identified.html', 'http://[email protected]:8083/tests/identified.html'],
2020
['http://testuser:[email protected]:8083/tests/authenticated.html', 'http://testuser:[email protected]:8083/tests/authenticated.html'],
21+
['http://testuser:[email protected]:8083/tests/authenticated.html', 'http://testuser:[email protected]:8083/tests/authenticated.html'],
2122
];
2223
}
2324

@@ -54,17 +55,22 @@ public function testDomain()
5455
$url = new Embed\Url('http://www.domain.com');
5556

5657
$this->assertSame('domain', $url->getDomain());
57-
$this->assertSame('domain.com', $url->getDomain(1));
58+
$this->assertSame('domain.com', $url->getDomain(true));
5859

5960
$url = new Embed\Url('http://www.domain.co.uk');
6061

6162
$this->assertSame('domain', $url->getDomain());
62-
$this->assertSame('domain.co.uk', $url->getDomain(1));
63+
$this->assertSame('domain.co.uk', $url->getDomain(true));
6364

6465
$url = new Embed\Url('http://www.domain.com.au');
6566

6667
$this->assertSame('domain', $url->getDomain());
67-
$this->assertSame('domain.com.au', $url->getDomain(1));
68+
$this->assertSame('domain.com.au', $url->getDomain(true));
69+
70+
$url = new Embed\Url('http://www.redrooster.org.uk');
71+
72+
$this->assertSame('redrooster', $url->getDomain());
73+
$this->assertSame('redrooster.org.uk', $url->getDomain(true));
6874
}
6975

7076
public function testPathsWithDots()

0 commit comments

Comments
 (0)