Skip to content

check that properties is an array before accessing #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1413,13 +1413,13 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
// Note: handling microformat nesting under multiple conflicting prefixes is not currently specified by the mf2 parsing spec.
$prefixSpecificResult = $result;
if (in_array('p-', $prefixes)) {
$prefixSpecificResult['value'] = (empty($prefixSpecificResult['properties']['name'][0])) ? $this->parseP($node) : $prefixSpecificResult['properties']['name'][0];
$prefixSpecificResult['value'] = (!is_array($prefixSpecificResult['properties']) || empty($prefixSpecificResult['properties']['name'][0])) ? $this->parseP($node) : $prefixSpecificResult['properties']['name'][0];
} elseif (in_array('e-', $prefixes)) {
$eParsedResult = $this->parseE($node);
$prefixSpecificResult['html'] = $eParsedResult['html'];
$prefixSpecificResult['value'] = $eParsedResult['value'];
} elseif (in_array('u-', $prefixes)) {
$prefixSpecificResult['value'] = (empty($result['properties']['url'])) ? $this->parseU($node) : reset($result['properties']['url']);
$prefixSpecificResult['value'] = (!is_array($result['properties']) || empty($result['properties']['url'])) ? $this->parseU($node) : reset($result['properties']['url']);
} elseif (in_array('dt-', $prefixes)) {
$parsed_property = $this->parseDT($node);
$prefixSpecificResult['value'] = ($parsed_property) ? $parsed_property : '';
Expand Down
21 changes: 20 additions & 1 deletion tests/Mf2/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,26 @@ public function testNotMutatingPassedInDOM() {
$this->assertEquals($refDoc, $inputDoc, 'Parsing mutated the DOMDocument.');
}

/**
public function testNoImpliedURLForEmptyProperties() {
// In the 0.4.5 release, this caused an error
// https://github.com/microformats/php-mf2/issues/196

$input = <<<EOD
<div class="h-entry">
<li class="h-cite u-comment">
<div class="vcard"></div>
</li>
</div>
EOD;

$output = Mf2\parse($input);
$this->assertInternalType('array', $output['items'][0]['properties']['comment'][0]['properties']);
$this->assertInternalType('array', $output['items'][0]['properties']['comment'][0]['children'][0]['properties']);
$this->assertEmpty($output['items'][0]['properties']['comment'][0]['properties']);
$this->assertEmpty($output['items'][0]['properties']['comment'][0]['children'][0]['properties']);
}

/**
* Make sure day of year passed to normalizeOrdinalDate() is valid
* @see https://github.com/indieweb/php-mf2/issues/167
*/
Expand Down