From 39e628d5b60f3b64aa6ad54af6ec44402889ea10 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Wed, 3 Feb 2016 12:21:40 -0800 Subject: [PATCH] target_domain bug fix: require exact parent domain in subdomain check --- controllers/API.php | 2 +- tests/APITest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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();