Browse Source

fix sending a single target parameter

main
Aaron Parecki 8 years ago
parent
commit
c443484141
2 changed files with 23 additions and 3 deletions
  1. +11
    -3
      controllers/API.php
  2. +12
    -0
      tests/APITest.php

+ 11
- 3
controllers/API.php View File

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

+ 12
- 0
tests/APITest.php View File

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

Loading…
Cancel
Save