Skip to content

Commit 31ca035

Browse files
committed
Test and fix for duplicate URLs in the rels object
1 parent f2289a8 commit 31ca035

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Mf2/Parser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,11 @@ public function parseRelsAndAlternates() {
12951295
}
12961296

12971297
foreach ($linkRels as $rel) {
1298-
$rels[$rel][] = $href;
1298+
if (!array_key_exists($rel, $rels)) {
1299+
$rels[$rel] = array($href);
1300+
} elseif (!in_array($href, $rels[$rel])) {
1301+
$rels[$rel][] = $href;
1302+
}
12991303
}
13001304

13011305
if (!array_key_exists($href, $rel_urls)) {

tests/Mf2/RelTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,13 @@ public function testRelURLsInfoMergesCorrectly() {
200200
$this->assertEquals($output['rel-urls']['#']['text'], 'This nodeValue');
201201
}
202202

203+
public function testRelURLsNoDuplicates() {
204+
$input = '<a href="#a" rel="a"></a>
205+
<a href="#b" rel="a"></a>
206+
<a href="#a" rel="a"></a>';
207+
$parser = new Parser($input);
208+
$output = $parser->parse();
209+
$this->assertEquals($output['rels']['a'], ['#a', '#b']);
210+
}
211+
203212
}

0 commit comments

Comments
 (0)