Skip to content

Commit 64e7966

Browse files
committed
Never do falsy checks on strings
1 parent 108fbf0 commit 64e7966

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Mf2/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,8 @@ public function parseRelsAndAlternates() {
12771277
$rel_attributes['type'] = $hyperlink->getAttribute('type');
12781278
}
12791279

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

12841284
if ($this->enableAlternates) {

tests/Mf2/RelTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,14 @@ public function testRelURLsNoDuplicates() {
209209
$this->assertEquals($output['rels']['a'], array('#a', '#b'));
210210
}
211211

212+
public function testRelURLsFalsyTextVSEmpty() {
213+
$input = '<a href="#a" rel="a">0</a>
214+
<a href="#b" rel="b"></a>';
215+
$parser = new Parser($input);
216+
$output = $parser->parse();
217+
$this->assertArrayHasKey('text', $output['rel-urls']['#a']);
218+
$this->assertEquals($output['rel-urls']['#a']['text'], '0');
219+
$this->assertArrayNotHasKey('text', $output['rel-urls']['#b']);
220+
}
221+
212222
}

0 commit comments

Comments
 (0)