Skip to content

Commit daf09fb

Browse files
authored
Merge pull request #202 from gRegorLove/issue195
Fix backcompat parsing for geo property
2 parents 966bd85 + e84b4e9 commit daf09fb

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Mf2/Parser.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,9 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
10711071

10721072
// Do we need to imply a name property?
10731073
// if no explicit "name" property, and no other p-* or e-* properties, and no nested microformats,
1074-
if (!array_key_exists('name', $return) && !in_array('p-', $prefixes) && !in_array('e-', $prefixes) && !$has_nested_mf && !$is_backcompat) {
1074+
if (!array_key_exists('name', $return) && !in_array('p-', $prefixes)
1075+
&& !in_array('e-', $prefixes) && !$has_nested_mf
1076+
&& !$is_backcompat && empty($this->upgraded[$e])) {
10751077
$name = false;
10761078
// img.h-x[alt] or area.h-x[alt]
10771079
if (($e->tagName === 'img' || $e->tagName === 'area') && $e->hasAttribute('alt')) {
@@ -1410,7 +1412,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
14101412
$recurse = $this->parse_recursive($node, $depth + 1);
14111413

14121414
// set bool flag for nested mf
1413-
$has_nested_mf = ($recurse);
1415+
$has_nested_mf = (bool) $recurse;
14141416

14151417
// parse for root mf
14161418
$result = $this->parseH($node, $is_backcompat, $has_nested_mf);
@@ -1827,7 +1829,8 @@ public function query($expression, $context = null) {
18271829
'replace' => 'p-label'
18281830
),
18291831
'geo' => array(
1830-
'replace' => 'p-geo h-geo'
1832+
'replace' => 'p-geo h-geo',
1833+
'context' => 'geo'
18311834
),
18321835
'latitude' => array(
18331836
'replace' => 'p-latitude'

tests/Mf2/ClassicMicroformatsTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -992,5 +992,18 @@ public function testBackcompatMultipleRoots() {
992992
$this->assertContains('h-entry name', $result['items'][0]['properties']['name']);
993993
}
994994

995+
/**
996+
* @see https://github.com/microformats/php-mf2/issues/195
997+
*/
998+
public function testVcardGeoNoImpliedName() {
999+
$input = '<div class="vcard">
1000+
<div class="fn">John Doe</div>
1001+
<div>Location: <abbr class="geo" title="30.267991;-97.739568">Brighton</abbr></div>
1002+
</div>';
1003+
$parser = new Parser($input, 'https://example.com');
1004+
$output = $parser->parse();
1005+
1006+
$this->assertArrayNotHasKey('name', $output['items'][0]['properties']['geo'][0]['properties']);
1007+
}
9951008
}
9961009

0 commit comments

Comments
 (0)