Skip to content

Commit

Permalink
Add failing test and fix for implied URL with blank href
Browse files Browse the repository at this point in the history
  • Loading branch information
gRegorLove committed Jun 4, 2017
1 parent e7c0cac commit 2755bdb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {

// Check for u-url
if (!array_key_exists('url', $return) && !$is_backcompat) {
$url = null;
// Look for img @src
if ($e->tagName == 'a' or $e->tagName == 'area') {
$url = $e->getAttribute('href');
Expand All @@ -1073,7 +1074,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
}
}

if (!empty($url)) {
if (!is_null($url)) {
$return['url'][] = $this->resolveUrl($url);
}
}
Expand Down
29 changes: 28 additions & 1 deletion tests/Mf2/ParseUTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ public function testParseUWithSpaces() {
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
$this->assertEquals('http://example.com', $output['items'][0]['properties']['url'][0]);
}


/**
* @see https://github.com/indieweb/php-mf2/issues/130
*/
public function testImpliedUWithEmptyHref() {
$input = '<a class="h-card" href="">Jane Doe</a>
<area class="h-card" href="" alt="Jane Doe"/ >
<div class="h-card" ><a href="">Jane Doe</a><p></p></div>
<div class="h-card" ><area href="">Jane Doe</area><p></p></div>
<div class="h-card" ><a class="h-card" href="">Jane Doe</a><p></p></div>';
$parser = new Parser($input, 'http://example.com');
$output = $parser->parse();

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

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

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

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

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

}

0 comments on commit 2755bdb

Please sign in to comment.