Browse Source

Merge pull request #9 from snarfed/subdomain

target_domain bug fix: require exact parent domain in subdomain check
main
Aaron Parecki 8 years ago
parent
commit
50ef6256f0
2 changed files with 11 additions and 1 deletions
  1. +1
    -1
      controllers/API.php
  2. +10
    -0
      tests/APITest.php

+ 1
- 1
controllers/API.php View File

@ -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;
}
}

+ 10
- 0
tests/APITest.php View File

@ -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();

Loading…
Cancel
Save