diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 9835ce8..51447a4 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -1164,8 +1164,8 @@ public function parseImpliedPhoto(\DOMElement $e) { $xpaths = array( './img', './object', - './*[count(preceding-sibling::*)+count(following-sibling::*)=0]/img', - './*[count(preceding-sibling::*)+count(following-sibling::*)=0]/object', + './*[not(contains(concat(" ", @class), " h-"))]/img[count(preceding-sibling::img)+count(following-sibling::img)=0]', + './*[not(contains(concat(" ", @class), " h-"))]/object[count(preceding-sibling::object)+count(following-sibling::object)=0]', ); foreach ($xpaths as $path) { diff --git a/tests/Mf2/ParseImpliedTest.php b/tests/Mf2/ParseImpliedTest.php index 26badbf..48a821c 100644 --- a/tests/Mf2/ParseImpliedTest.php +++ b/tests/Mf2/ParseImpliedTest.php @@ -273,6 +273,26 @@ public function testIgnoredPhotoIfNestedObjectHasHClass() { $this->assertArrayNotHasKey('photo', $result['items'][0]['properties']); } + /** + * @see https://github.com/indieweb/php-mf2/issues/176 + */ + public function testIgnoredPhotoImgInNestedH() { + $input = '
'; + $result = Mf2\parse($input); + + $this->assertArrayNotHasKey('photo', $result['items'][0]['properties']); + } + + /** + * @see https://github.com/indieweb/php-mf2/issues/176 + */ + public function testIgnoredPhotoObjectInNestedH() { + $input = '
John Doe
'; + $result = Mf2\parse($input); + + $this->assertArrayNotHasKey('photo', $result['items'][0]['properties']); + } + /** * Imply properties only on explicit h-x class name root microformat element (no backcompat roots) * @see http://microformats.org/wiki/microformats2-parsing#parsing_for_implied_properties