diff --git a/Mf2/Parser.php b/Mf2/Parser.php index f8b29b7..2192b8c 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -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 : ''; diff --git a/tests/Mf2/ParserTest.php b/tests/Mf2/ParserTest.php index 0f480cf..f30e2bf 100644 --- a/tests/Mf2/ParserTest.php +++ b/tests/Mf2/ParserTest.php @@ -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; + + $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 */