diff --git a/controllers/Parse.php b/controllers/Parse.php index eebe12a..0905a13 100644 --- a/controllers/Parse.php +++ b/controllers/Parse.php @@ -192,6 +192,16 @@ class Parse { $xpath = new DOMXPath($doc); + // Check for meta http equiv and replace the status code if present + foreach($xpath->query('//meta[@http-equiv=\'status\']') as $el) { + $equivStatus = ''.$el->getAttribute('content'); + if($equivStatus && is_string($equivStatus)) { + if(preg_match('/^(\d+)/', $equivStatus, $match)) { + $result['code'] = (int)$match[1]; + } + } + } + // If a target parameter was provided, make sure a link to it exists on the page if($target=$request->get('target')) { $found = []; @@ -228,16 +238,6 @@ class Parse { } } - // Check for meta http equiv and replace the status code if present - foreach($xpath->query('//meta[@http-equiv=\'status\']') as $el) { - $equivStatus = ''.$el->getAttribute('content'); - if($equivStatus && is_string($equivStatus)) { - if(preg_match('/^(\d+)/', $equivStatus, $match)) { - $result['code'] = (int)$match[1]; - } - } - } - // If the URL has a fragment ID, find the DOM starting at that node and parse it instead $html = $result['body']; diff --git a/tests/FetchTest.php b/tests/FetchTest.php index fe84f0c..7cebeef 100644 --- a/tests/FetchTest.php +++ b/tests/FetchTest.php @@ -116,4 +116,21 @@ class FetchTest extends PHPUnit_Framework_TestCase { $this->assertEquals(410, $data->code); $this->assertEquals('This post has been deleted.', $data->data->content->text); } + + public function testMetaEquivDeletedTargetProvided() { + // for example when verifying a webmention but the source was replaced with an html deleted page + + $url = 'http://source.example.com/deleted'; + $response = $this->parse([ + 'url' => $url, + 'target' => 'http://example.com/' + ]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body); + $this->assertObjectHasAttribute('error', $data); + $this->assertEquals('no_link_found', $data->error); + $this->assertEquals(410, $data->code); + } }