diff --git a/Mf2/Parser.php b/Mf2/Parser.php index fe5590b..5701e02 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -1047,7 +1047,9 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf = // Do we need to imply a name property? // if no explicit "name" property, and no other p-* or e-* properties, and no nested microformats, - if (!array_key_exists('name', $return) && !in_array('p-', $prefixes) && !in_array('e-', $prefixes) && !$has_nested_mf && !$is_backcompat) { + if (!array_key_exists('name', $return) && !in_array('p-', $prefixes) + && !in_array('e-', $prefixes) && !$has_nested_mf + && !$is_backcompat && empty($this->upgraded[$e])) { $name = false; // img.h-x[alt] or area.h-x[alt] if (($e->tagName === 'img' || $e->tagName === 'area') && $e->hasAttribute('alt')) { @@ -1384,7 +1386,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) { $recurse = $this->parse_recursive($node, $depth + 1); // set bool flag for nested mf - $has_nested_mf = ($recurse); + $has_nested_mf = (bool) $recurse; // parse for root mf $result = $this->parseH($node, $is_backcompat, $has_nested_mf); @@ -1800,7 +1802,8 @@ public function query($expression, $context = null) { 'replace' => 'p-label' ), 'geo' => array( - 'replace' => 'p-geo h-geo' + 'replace' => 'p-geo h-geo', + 'context' => 'geo' ), 'latitude' => array( 'replace' => 'p-latitude' diff --git a/tests/Mf2/ClassicMicroformatsTest.php b/tests/Mf2/ClassicMicroformatsTest.php index 97e7a7a..0150e08 100644 --- a/tests/Mf2/ClassicMicroformatsTest.php +++ b/tests/Mf2/ClassicMicroformatsTest.php @@ -992,5 +992,18 @@ public function testBackcompatMultipleRoots() { $this->assertContains('h-entry name', $result['items'][0]['properties']['name']); } + /** + * @see https://github.com/microformats/php-mf2/issues/195 + */ + public function testVcardGeoNoImpliedName() { + $input = '
+
John Doe
+
Location: Brighton
+
'; + $parser = new Parser($input, 'https://example.com'); + $output = $parser->parse(); + + $this->assertArrayNotHasKey('name', $output['items'][0]['properties']['geo'][0]['properties']); + } }