Skip to content

Commit

Permalink
Never do falsy checks on strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegnat committed Mar 22, 2018
1 parent 108fbf0 commit 64e7966
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,8 @@ public function parseRelsAndAlternates() {
$rel_attributes['type'] = $hyperlink->getAttribute('type');
}

if ($hyperlink->nodeValue) {
$rel_attributes['text'] = $hyperlink->nodeValue;
if (strlen($hyperlink->textContent) > 0) {
$rel_attributes['text'] = $hyperlink->textContent;
}

if ($this->enableAlternates) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Mf2/RelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,14 @@ public function testRelURLsNoDuplicates() {
$this->assertEquals($output['rels']['a'], array('#a', '#b'));
}

public function testRelURLsFalsyTextVSEmpty() {
$input = '<a href="#a" rel="a">0</a>
<a href="#b" rel="b"></a>';
$parser = new Parser($input);
$output = $parser->parse();
$this->assertArrayHasKey('text', $output['rel-urls']['#a']);
$this->assertEquals($output['rel-urls']['#a']['text'], '0');
$this->assertArrayNotHasKey('text', $output['rel-urls']['#b']);
}

}

0 comments on commit 64e7966

Please sign in to comment.