diff --git a/controllers/API.php b/controllers/API.php index 172e32d..62bcec1 100644 --- a/controllers/API.php +++ b/controllers/API.php @@ -103,7 +103,7 @@ class API { foreach($xpath->query('//a[@href]') as $href) { $url = $href->getAttribute('href'); $domain = parse_url($url, PHP_URL_HOST); - if($url == $target || $domain == $target_domain || str_ends_with($domain, $target_domain)) { + if($url == $target || $domain == $target_domain || str_ends_with($domain, '.' . $target_domain)) { $found[$url] = null; } } diff --git a/tests/APITest.php b/tests/APITest.php index 526ce28..c82bcbe 100644 --- a/tests/APITest.php +++ b/tests/APITest.php @@ -214,6 +214,16 @@ class APITest extends PHPUnit_Framework_TestCase { $this->_assertNotQueued('http://source.example.com/multipletest', 'http://source.example.com/relativelink'); } + public function testTargetDomainSubdomainCheck() { + $this->_createExampleAccount(); + + $response = $this->webmention(['token'=>'a','source'=>'http://source.example.com/multipletest','target_domain'=>'ample.com']); + $body = $response->getContent(); + $this->assertEquals(400, $response->getStatusCode()); + $data = json_decode($response->getContent()); + $this->assertEquals('no_link_found', $data->error); + } + public function testStatusNotFound() { $this->_createExampleAccount();