Skip to content

Commit 59383b4

Browse files
authored
Merge pull request #181 from gRegorLove/issue156
Fix parsing multiple mf1 roots on same element
2 parents 3610bd6 + 18a0d38 commit 59383b4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Mf2/Parser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,8 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
14991499
$mf1Classes = array_intersect($classes, array_keys($this->classicRootMap));
15001500
}
15011501

1502+
$elHasMf2 = $this->hasRootMf2($el);
1503+
15021504
foreach ($mf1Classes as $classname) {
15031505
// special handling for specific properties
15041506
switch ( $classname )
@@ -1593,7 +1595,7 @@ public function backcompat(DOMElement $el, $context = '', $isParentMf2 = false)
15931595
}
15941596
}
15951597

1596-
if ( empty($context) && isset($this->classicRootMap[$classname]) && !$this->hasRootMf2($el) ) {
1598+
if ( empty($context) && isset($this->classicRootMap[$classname]) && !$elHasMf2 ) {
15971599
$this->addMfClasses($el, $this->classicRootMap[$classname]);
15981600
}
15991601
}

tests/Mf2/ClassicMicroformatsTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,5 +971,26 @@ public function testRelTagTrailingSlash() {
971971
$this->assertContains('phpmf2', $output['items'][1]['properties']['category']);
972972
$this->assertContains('mf2py', $output['items'][1]['properties']['category']);
973973
}
974+
975+
/**
976+
* Upgrade multiple mf1 roots on the same element
977+
* @see https://github.com/indieweb/php-mf2/issues/156
978+
*/
979+
public function testBackcompatMultipleRoots() {
980+
$input = '<article class="vevent hentry">
981+
<span class="entry-title">h-entry name</span>
982+
<span class="summary">h-event name</span>
983+
</article>';
984+
$result = Mf2\parse($input);
985+
986+
$this->assertCount(2, $result['items'][0]['type']);
987+
$this->assertContains('h-event', $result['items'][0]['type']);
988+
$this->assertContains('h-entry', $result['items'][0]['type']);
989+
$this->assertArrayHasKey('name', $result['items'][0]['properties']);
990+
$this->assertCount(2, $result['items'][0]['properties']['name']);
991+
$this->assertContains('h-event name', $result['items'][0]['properties']['name']);
992+
$this->assertContains('h-entry name', $result['items'][0]['properties']['name']);
993+
}
994+
974995
}
975996

0 commit comments

Comments
 (0)