Skip to content

Commit

Permalink
Move resolve step last in u-* parsing
Browse files Browse the repository at this point in the history
This matches the proposed parsing change from
microformats/microformats2-parsing#10.
  • Loading branch information
Zegnat committed Apr 20, 2018
1 parent e8da04f commit a60905d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
19 changes: 6 additions & 13 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,23 +618,16 @@ public function parseU(\DOMElement $u) {
$uValue = $u->getAttribute('poster');
} elseif ($u->tagName == 'object' and $u->hasAttribute('data')) {
$uValue = $u->getAttribute('data');
}

if (isset($uValue)) {
return $this->resolveUrl($uValue);
}

$classTitle = $this->parseValueClassTitle($u);

if ($classTitle !== null) {
return $classTitle;
} elseif (($classTitle = $this->parseValueClassTitle($u)) !== null) {
$uValue = $classTitle;
} elseif (($u->tagName == 'abbr' or $u->tagName == 'link') and $u->hasAttribute('title')) {
return $u->getAttribute('title');
$uValue = $u->getAttribute('title');
} elseif (in_array($u->tagName, array('data', 'input')) and $u->hasAttribute('value')) {
return $u->getAttribute('value');
$uValue = $u->getAttribute('value');
} else {
return $this->textContent($u);
$uValue = $this->textContent($u);
}
return $this->resolveUrl($uValue);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion tests/Mf2/ParseUTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testParseUHandlesMissingHrefAttribute() {
$output = $parser->parse();

$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('Awesome example website', $output['items'][0]['properties']['url'][0]);
$this->assertEquals('http://example.com/Awesome example website', $output['items'][0]['properties']['url'][0]);
}

/**
Expand Down Expand Up @@ -296,4 +296,12 @@ public function testValueFromLinkTag() {
$this->assertEquals('Example.com homepage', $output['items'][0]['properties']['name'][0]);
}

public function testResolveFromDataElement() {
$parser = new Parser('<div class="h-test"><data class="u-url" value="relative.html"></data></div>', 'https://example.com/index.html');
$output = $parser->parse();

$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('https://example.com/relative.html', $output['items'][0]['properties']['url'][0]);
}

}

0 comments on commit a60905d

Please sign in to comment.