From 9fb8a0c9a3085e342e31278c80c684ed310575bf Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 11 Apr 2020 15:56:12 -0700 Subject: [PATCH] fix the bug where some mf2 JSON requests were not parsed correctly --- lib/XRay/Parser.php | 16 +++++++++------- tests/ParseTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/XRay/Parser.php b/lib/XRay/Parser.php index 108ec6f..674def1 100644 --- a/lib/XRay/Parser.php +++ b/lib/XRay/Parser.php @@ -83,7 +83,7 @@ class Parser { $body = $http_response['body']; // Check if an mf2 JSON object was passed in - if(is_array($body) && isset($body['items']) && isset($body['rels']) && isset($body['rel-urls'])) { + if(is_array($body) && isset($body['items'])) { $data = Formats\Mf2::parse($http_response, $this->http, $opts); if($data == false) { $data = [ @@ -103,17 +103,19 @@ class Parser { return $data; } - if(substr($body, 0, 5) == 'assertEquals('http://one.example.com/test', $data['data']['url']); } + public function testInputIsJSON() { + $url = 'http://example.com/entry'; + + $mf2json = ['items' => [ + [ + 'type' => ['h-entry'], + 'properties' => [ + 'content' => [['html' => 'Hello World']] + ] + ] + ]]; + + $response = $this->parse([ + 'body' => $mf2json, + 'url' => $url, + ]); + + $body = $response->getContent(); + $data = json_decode($body, true); + + $this->assertEquals('mf2+json', $data['source-format']); + $this->assertEquals('Hello World', $data['data']['content']['text']); + } + public function testInputIsParsedMf2() { $html = '

Hello World

'; $mf2 = Mf2\parse($html, 'http://example.com/entry');