Skip to content

Commit

Permalink
Merge pull request #90 from gRegorLove/issue89
Browse files Browse the repository at this point in the history
Added failing test and fix for #89.
  • Loading branch information
barnabywalters committed Apr 17, 2016
2 parents d653341 + 7a4357a commit 0762d6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,14 @@ public function innerText($el, $implied=false) {
if (in_array(strtolower($el->tagName), $excludeTags)) {
return $out;
} else if ($el->tagName == 'img') {
if ($el->getAttribute('alt') !== '') {
if ($el->hasAttribute('alt')) {
return $el->getAttribute('alt');
} else if (!$implied && $el->getAttribute('src') !== '') {
} else if (!$implied && $el->hasAttribute('src')) {
return $this->resolveUrl($el->getAttribute('src'));
}
} else if ($el->tagName == 'area' and $el->getAttribute('alt') !== '') {
} else if ($el->tagName == 'area' and $el->hasAttribute('alt')) {
return $el->getAttribute('alt');
} else if ($el->tagName == 'abbr' and $el->getAttribute('title') !== '') {
} else if ($el->tagName == 'abbr' and $el->hasAttribute('title')) {
return $el->getAttribute('title');
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Mf2/ParsePTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,15 @@ public function testBrWhitespaceIssue69() {
$this->assertEquals('Street Name 9' . "\n" . '12345 NY, USA', $result['items'][0]['properties']['name'][0]);
}

/**
* @see https://github.com/indieweb/php-mf2/issues/89
*/
public function testEmptyAlt() {
$input = '<div class="p-author h-card"><a href="/" class="p-org p-name"><img class="u-logo" src="/static/logo.jpg" alt="" />mention.tech</a></div>';
$result = Mf2\parse($input);

$this->assertEquals('mention.tech', $result['items'][0]['properties']['org'][0]);
$this->assertEquals('mention.tech', $result['items'][0]['properties']['name'][0]);
}

}

0 comments on commit 0762d6b

Please sign in to comment.