Skip to content

Commit fba7f55

Browse files
authored
Merge pull request #177 from gRegorLove/issue176
Fix XPaths used in implied photo parsing
2 parents 59383b4 + 5c4c3e9 commit fba7f55

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Mf2/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ public function parseImpliedPhoto(\DOMElement $e) {
11641164
$xpaths = array(
11651165
'./img',
11661166
'./object',
1167-
'./*[count(preceding-sibling::*)+count(following-sibling::*)=0]/img',
1168-
'./*[count(preceding-sibling::*)+count(following-sibling::*)=0]/object',
1167+
'./*[not(contains(concat(" ", @class), " h-"))]/img[count(preceding-sibling::img)+count(following-sibling::img)=0]',
1168+
'./*[not(contains(concat(" ", @class), " h-"))]/object[count(preceding-sibling::object)+count(following-sibling::object)=0]',
11691169
);
11701170

11711171
foreach ($xpaths as $path) {

tests/Mf2/ParseImpliedTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,26 @@ public function testIgnoredPhotoIfNestedObjectHasHClass() {
273273
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
274274
}
275275

276+
/**
277+
* @see https://github.com/indieweb/php-mf2/issues/176
278+
*/
279+
public function testIgnoredPhotoImgInNestedH() {
280+
$input = '<div class="h-entry"> <div class="u-comment h-cite"> <img src="/image.jpg"> </div> </div>';
281+
$result = Mf2\parse($input);
282+
283+
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
284+
}
285+
286+
/**
287+
* @see https://github.com/indieweb/php-mf2/issues/176
288+
*/
289+
public function testIgnoredPhotoObjectInNestedH() {
290+
$input = '<div class="h-entry"> <div class="u-comment h-cite"> <object data="/image2.jpg">John Doe</object> </div> </div>';
291+
$result = Mf2\parse($input);
292+
293+
$this->assertArrayNotHasKey('photo', $result['items'][0]['properties']);
294+
}
295+
276296
/**
277297
* Imply properties only on explicit h-x class name root microformat element (no backcompat roots)
278298
* @see http://microformats.org/wiki/microformats2-parsing#parsing_for_implied_properties

0 commit comments

Comments
 (0)