Skip to content

Commit

Permalink
Merge pull request #177 from gRegorLove/issue176
Browse files Browse the repository at this point in the history
Fix XPaths used in implied photo parsing
  • Loading branch information
aaronpk committed Aug 1, 2018
2 parents 59383b4 + 5c4c3e9 commit fba7f55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Mf2/ParseImpliedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="h-entry"> <div class="u-comment h-cite"> <img src="/image.jpg"> </div> </div>';
$result = Mf2\parse($input);

$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
}

/**
* @see https://github.com/indieweb/php-mf2/issues/176
*/
public function testIgnoredPhotoObjectInNestedH() {
$input = '<div class="h-entry"> <div class="u-comment h-cite"> <object data="/image2.jpg">John Doe</object> </div> </div>';
$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
Expand Down

0 comments on commit fba7f55

Please sign in to comment.