Skip to content

Commit

Permalink
Add failing test and fix for microformats#195
Browse files Browse the repository at this point in the history
  • Loading branch information
gRegorLove committed Aug 25, 2018
1 parent 00b70ee commit e84b4e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions tests/Mf2/ClassicMicroformatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="vcard">
<div class="fn">John Doe</div>
<div>Location: <abbr class="geo" title="30.267991;-97.739568">Brighton</abbr></div>
</div>';
$parser = new Parser($input, 'https://example.com');
$output = $parser->parse();

$this->assertArrayNotHasKey('name', $output['items'][0]['properties']['geo'][0]['properties']);
}
}

0 comments on commit e84b4e9

Please sign in to comment.