diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index e0d3e4c..8694e58 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -323,16 +323,20 @@ class Mf2 extends Format { } private static function collectArrayURLValues($properties, $item, &$data, &$refs, &$http) { + $keys = []; + foreach($properties as $p) { if(array_key_exists($p, $item['properties'])) { foreach($item['properties'][$p] as $v) { if(is_string($v) && self::isURL($v)) { if(!array_key_exists($p, $data)) $data[$p] = []; $data[$p][] = $v; + $keys[] = $p; } elseif(self::isMicroformat($v) && ($u=self::getPlaintext($v, 'url')) && self::isURL($u)) { if(!array_key_exists($p, $data)) $data[$p] = []; $data[$p][] = $u; + $keys[] = $p; // parse the object and put the result in the "refs" object $ref = self::parse(['items'=>[$v]], $u, $http); if($ref) { @@ -340,7 +344,12 @@ class Mf2 extends Format { } } } - } + } + } + + // Remove duplicate values + foreach(array_unique($keys) as $key) { + $data[$key] = array_unique($data[$key]); } } diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 24bda5c..a479ad3 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -660,4 +660,28 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertObjectNotHasAttribute('photo', $data->data); } + public function testDuplicateReplyURLValues() { + $url = 'http://source.example.com/duplicate-in-reply-to-urls'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]); + $this->assertEquals(1, count($data['data']['in-reply-to'])); + } + + public function testDuplicateLikeOfURLValues() { + $url = 'http://source.example.com/duplicate-like-of-urls'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('http://example.com/100', $data['data']['like-of'][0]); + $this->assertEquals(1, count($data['data']['like-of'])); + } + } diff --git a/tests/data/source.example.com/duplicate-in-reply-to-urls b/tests/data/source.example.com/duplicate-in-reply-to-urls new file mode 100644 index 0000000..74353a1 --- /dev/null +++ b/tests/data/source.example.com/duplicate-in-reply-to-urls @@ -0,0 +1,19 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 +Connection: keep-alive + + + + Test + + + in reply to +
+ this post +
+

This page has duplicate in-reply-to values.

+ permalink + + diff --git a/tests/data/source.example.com/duplicate-like-of-urls b/tests/data/source.example.com/duplicate-like-of-urls new file mode 100644 index 0000000..527530a --- /dev/null +++ b/tests/data/source.example.com/duplicate-like-of-urls @@ -0,0 +1,19 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 +Connection: keep-alive + + + + Test + + + liked + a post +
+ this post +
+ permalink + +