Skip to content

Commit 8247a27

Browse files
authored
Merge pull request #197 from aaronpk/issue-196
check that properties is an array before accessing
2 parents ba9d428 + 500445d commit 8247a27

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Mf2/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,13 +1413,13 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
14131413
// Note: handling microformat nesting under multiple conflicting prefixes is not currently specified by the mf2 parsing spec.
14141414
$prefixSpecificResult = $result;
14151415
if (in_array('p-', $prefixes)) {
1416-
$prefixSpecificResult['value'] = (empty($prefixSpecificResult['properties']['name'][0])) ? $this->parseP($node) : $prefixSpecificResult['properties']['name'][0];
1416+
$prefixSpecificResult['value'] = (!is_array($prefixSpecificResult['properties']) || empty($prefixSpecificResult['properties']['name'][0])) ? $this->parseP($node) : $prefixSpecificResult['properties']['name'][0];
14171417
} elseif (in_array('e-', $prefixes)) {
14181418
$eParsedResult = $this->parseE($node);
14191419
$prefixSpecificResult['html'] = $eParsedResult['html'];
14201420
$prefixSpecificResult['value'] = $eParsedResult['value'];
14211421
} elseif (in_array('u-', $prefixes)) {
1422-
$prefixSpecificResult['value'] = (empty($result['properties']['url'])) ? $this->parseU($node) : reset($result['properties']['url']);
1422+
$prefixSpecificResult['value'] = (!is_array($result['properties']) || empty($result['properties']['url'])) ? $this->parseU($node) : reset($result['properties']['url']);
14231423
} elseif (in_array('dt-', $prefixes)) {
14241424
$parsed_property = $this->parseDT($node);
14251425
$prefixSpecificResult['value'] = ($parsed_property) ? $parsed_property : '';

tests/Mf2/ParserTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,26 @@ public function testNotMutatingPassedInDOM() {
825825
$this->assertEquals($refDoc, $inputDoc, 'Parsing mutated the DOMDocument.');
826826
}
827827

828-
/**
828+
public function testNoImpliedURLForEmptyProperties() {
829+
// In the 0.4.5 release, this caused an error
830+
// https://github.com/microformats/php-mf2/issues/196
831+
832+
$input = <<<EOD
833+
<div class="h-entry">
834+
<li class="h-cite u-comment">
835+
<div class="vcard"></div>
836+
</li>
837+
</div>
838+
EOD;
839+
840+
$output = Mf2\parse($input);
841+
$this->assertInternalType('array', $output['items'][0]['properties']['comment'][0]['properties']);
842+
$this->assertInternalType('array', $output['items'][0]['properties']['comment'][0]['children'][0]['properties']);
843+
$this->assertEmpty($output['items'][0]['properties']['comment'][0]['properties']);
844+
$this->assertEmpty($output['items'][0]['properties']['comment'][0]['children'][0]['properties']);
845+
}
846+
847+
/**
829848
* Make sure day of year passed to normalizeOrdinalDate() is valid
830849
* @see https://github.com/indieweb/php-mf2/issues/167
831850
*/

0 commit comments

Comments
 (0)