Browse Source

also check for opening rss tag

closes #89
pull/94/head
Aaron Parecki 5 years ago
parent
commit
491f3796f8
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 345 additions and 0 deletions
  1. +6
    -0
      lib/XRay/Parser.php
  2. +10
    -0
      tests/FeedTest.php
  3. +329
    -0
      tests/data/feed.example.com/rss-no-xml-tag

+ 6
- 0
lib/XRay/Parser.php View File

@ -63,6 +63,12 @@ class Parser {
return Formats\XML::parse($http_response); return Formats\XML::parse($http_response);
} }
// Some feeds don't start with <?xml
$begin = trim(substr($body, 0, 40));
if(substr($begin, 0, 4) == '<rss') {
return Formats\XML::parse($http_response);
}
if(substr($body, 0, 1) == '{') { if(substr($body, 0, 1) == '{') {
$parsed = json_decode($body, true); $parsed = json_decode($body, true);
if($parsed && isset($parsed['version']) && $parsed['version'] == 'https://jsonfeed.org/version/1') { if($parsed && isset($parsed['version']) && $parsed['version'] == 'https://jsonfeed.org/version/1') {

+ 10
- 0
tests/FeedTest.php View File

@ -465,4 +465,14 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Barnaby Walters', $item->author->name); $this->assertEquals('Barnaby Walters', $item->author->name);
$this->assertEquals('https://waterpigs.co.uk', $item->author->url); $this->assertEquals('https://waterpigs.co.uk', $item->author->url);
} }
public function testRSSWithNoXMLTag() {
$url = 'http://feed.example.com/rss-no-xml-tag';
$response = $this->parse(['url' => $url, 'expect' => 'feed']);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$this->assertEquals('feed', $data->type);
}
} }

+ 329
- 0
tests/data/feed.example.com/rss-no-xml-tag
File diff suppressed because it is too large
View File


Loading…
Cancel
Save