Skip to content

Commit 0762d6b

Browse files
Merge pull request #90 from gRegorLove/issue89
Added failing test and fix for #89.
2 parents d653341 + 7a4357a commit 0762d6b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Mf2/Parser.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,14 @@ public function innerText($el, $implied=false) {
409409
if (in_array(strtolower($el->tagName), $excludeTags)) {
410410
return $out;
411411
} else if ($el->tagName == 'img') {
412-
if ($el->getAttribute('alt') !== '') {
412+
if ($el->hasAttribute('alt')) {
413413
return $el->getAttribute('alt');
414-
} else if (!$implied && $el->getAttribute('src') !== '') {
414+
} else if (!$implied && $el->hasAttribute('src')) {
415415
return $this->resolveUrl($el->getAttribute('src'));
416416
}
417-
} else if ($el->tagName == 'area' and $el->getAttribute('alt') !== '') {
417+
} else if ($el->tagName == 'area' and $el->hasAttribute('alt')) {
418418
return $el->getAttribute('alt');
419-
} else if ($el->tagName == 'abbr' and $el->getAttribute('title') !== '') {
419+
} else if ($el->tagName == 'abbr' and $el->hasAttribute('title')) {
420420
return $el->getAttribute('title');
421421
}
422422
}

tests/Mf2/ParsePTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,15 @@ public function testBrWhitespaceIssue69() {
115115
$this->assertEquals('Street Name 9' . "\n" . '12345 NY, USA', $result['items'][0]['properties']['name'][0]);
116116
}
117117

118+
/**
119+
* @see https://github.com/indieweb/php-mf2/issues/89
120+
*/
121+
public function testEmptyAlt() {
122+
$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>';
123+
$result = Mf2\parse($input);
124+
125+
$this->assertEquals('mention.tech', $result['items'][0]['properties']['org'][0]);
126+
$this->assertEquals('mention.tech', $result['items'][0]['properties']['name'][0]);
127+
}
128+
118129
}

0 commit comments

Comments
 (0)