diff --git a/controllers/API.php b/controllers/API.php index 62bcec1..8e955bd 100644 --- a/controllers/API.php +++ b/controllers/API.php @@ -102,9 +102,17 @@ class API { $found = []; 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)) { - $found[$url] = null; + if($target) { + # target parameter was provided + if($url == $target) { + $found[$url] = null; + } + } elseif($target_domain) { + # target_domain parameter was provided + $domain = parse_url($url, PHP_URL_HOST); + if($domain && ($domain == $target_domain || str_ends_with($domain, '.' . $target_domain))) { + $found[$url] = null; + } } } diff --git a/tests/APITest.php b/tests/APITest.php index c82bcbe..103f097 100644 --- a/tests/APITest.php +++ b/tests/APITest.php @@ -169,6 +169,18 @@ class APITest extends PHPUnit_Framework_TestCase { $this->_assertQueued('http://source.example.com/basictest', 'http://target.example.com', $data->location); } + public function testTargetQueuesOnlyTargetWebmention() { + $this->_createExampleAccount(); + + $response = $this->webmention(['token'=>'a','source'=>'http://source.example.com/multipletest','target'=>'http://target.example.com']); + $this->assertEquals(201, $response->getStatusCode()); + $data = json_decode($response->getContent()); + $this->assertEquals(false, property_exists($data, 'error')); + $this->assertEquals('queued', $data->status); + $this->_assertQueued('http://source.example.com/multipletest', 'http://target.example.com', $data->location); + $this->_assertNotQueued('http://source.example.com/multipletest', '/relativelink'); + } + public function testTargetDomainQueuesOneWebmention() { $this->_createExampleAccount();