Browse Source

check for http-equiv for deleted posts when target URL provided

pull/39/head
Aaron Parecki 7 years ago
parent
commit
7ef9d2c936
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 27 additions and 10 deletions
  1. +10
    -10
      controllers/Parse.php
  2. +17
    -0
      tests/FetchTest.php

+ 10
- 10
controllers/Parse.php View File

@ -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'];

+ 17
- 0
tests/FetchTest.php View File

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

Loading…
Cancel
Save