Skip to content

Commit e84b4e9

Browse files
committed
Add failing test and fix for microformats#195
1 parent 00b70ee commit e84b4e9

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
@@ -1047,7 +1047,9 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf =
10471047

10481048
// Do we need to imply a name property?
10491049
// if no explicit "name" property, and no other p-* or e-* properties, and no nested microformats,
1050-
if (!array_key_exists('name', $return) && !in_array('p-', $prefixes) && !in_array('e-', $prefixes) && !$has_nested_mf && !$is_backcompat) {
1050+
if (!array_key_exists('name', $return) && !in_array('p-', $prefixes)
1051+
&& !in_array('e-', $prefixes) && !$has_nested_mf
1052+
&& !$is_backcompat && empty($this->upgraded[$e])) {
10511053
$name = false;
10521054
// img.h-x[alt] or area.h-x[alt]
10531055
if (($e->tagName === 'img' || $e->tagName === 'area') && $e->hasAttribute('alt')) {
@@ -1384,7 +1386,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
13841386
$recurse = $this->parse_recursive($node, $depth + 1);
13851387

13861388
// set bool flag for nested mf
1387-
$has_nested_mf = ($recurse);
1389+
$has_nested_mf = (bool) $recurse;
13881390

13891391
// parse for root mf
13901392
$result = $this->parseH($node, $is_backcompat, $has_nested_mf);
@@ -1800,7 +1802,8 @@ public function query($expression, $context = null) {
18001802
'replace' => 'p-label'
18011803
),
18021804
'geo' => array(
1803-
'replace' => 'p-geo h-geo'
1805+
'replace' => 'p-geo h-geo',
1806+
'context' => 'geo'
18041807
),
18051808
'latitude' => array(
18061809
'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)