Skip to content

Commit a51b22a

Browse files
authored
Merge pull request #187 from aaronpk/master
fix for parsing empty e- elements
2 parents 463351e + 1318854 commit a51b22a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Mf2/Parser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,9 @@ public function parseE(\DOMElement $e) {
853853
}
854854
$html = $e->ownerDocument->saveHtml($innerNodes);
855855
// Put the nodes back in place.
856-
$e->appendChild($innerNodes);
856+
if($innerNodes->hasChildNodes()) {
857+
$e->appendChild($innerNodes);
858+
}
857859

858860
$return = array(
859861
'html' => unicodeTrim($html),

tests/Mf2/ParserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ public function testParseE() {
8787
$this->assertEquals('Here is a load of embedded markup', $output['items'][0]['properties']['content'][0]['value']);
8888
}
8989

90+
public function testParseEmptyE() {
91+
$input = '<div class="h-entry"><div class="p-name">Name</div> <div class="e-content"></div></div>';
92+
//$parser = new Parser($input);
93+
$output = Mf2\parse($input);
94+
95+
$this->assertEquals('Name', $output['items'][0]['properties']['name'][0]);
96+
$this->assertArrayHasKey('content', $output['items'][0]['properties']);
97+
$this->assertEquals('', $output['items'][0]['properties']['content'][0]['html']);
98+
$this->assertEquals('', $output['items'][0]['properties']['content'][0]['value']);
99+
}
100+
90101
public function testParseEResolvesRelativeLinks() {
91102
$input = '<div class="h-entry"><p class="e-content">Blah blah <a href="/a-url">thing</a>. <object data="/object"></object> <img src="/img" /></p></div>';
92103
$parser = new Parser($input, 'http://example.com');

0 commit comments

Comments
 (0)