Skip to content

Commit c52fd0d

Browse files
authored
Merge pull request #170 from Zegnat/resolve-urls-late
Move resolve step last in u-* parsing
2 parents ae49928 + a60905d commit c52fd0d

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Mf2/Parser.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -618,23 +618,16 @@ public function parseU(\DOMElement $u) {
618618
$uValue = $u->getAttribute('poster');
619619
} elseif ($u->tagName == 'object' and $u->hasAttribute('data')) {
620620
$uValue = $u->getAttribute('data');
621-
}
622-
623-
if (isset($uValue)) {
624-
return $this->resolveUrl($uValue);
625-
}
626-
627-
$classTitle = $this->parseValueClassTitle($u);
628-
629-
if ($classTitle !== null) {
630-
return $classTitle;
621+
} elseif (($classTitle = $this->parseValueClassTitle($u)) !== null) {
622+
$uValue = $classTitle;
631623
} elseif (($u->tagName == 'abbr' or $u->tagName == 'link') and $u->hasAttribute('title')) {
632-
return $u->getAttribute('title');
624+
$uValue = $u->getAttribute('title');
633625
} elseif (in_array($u->tagName, array('data', 'input')) and $u->hasAttribute('value')) {
634-
return $u->getAttribute('value');
626+
$uValue = $u->getAttribute('value');
635627
} else {
636-
return $this->textContent($u);
628+
$uValue = $this->textContent($u);
637629
}
630+
return $this->resolveUrl($uValue);
638631
}
639632

640633
/**

tests/Mf2/ParseUTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testParseUHandlesMissingHrefAttribute() {
4747
$output = $parser->parse();
4848

4949
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
50-
$this->assertEquals('Awesome example website', $output['items'][0]['properties']['url'][0]);
50+
$this->assertEquals('http://example.com/Awesome example website', $output['items'][0]['properties']['url'][0]);
5151
}
5252

5353
/**
@@ -296,4 +296,12 @@ public function testValueFromLinkTag() {
296296
$this->assertEquals('Example.com homepage', $output['items'][0]['properties']['name'][0]);
297297
}
298298

299+
public function testResolveFromDataElement() {
300+
$parser = new Parser('<div class="h-test"><data class="u-url" value="relative.html"></data></div>', 'https://example.com/index.html');
301+
$output = $parser->parse();
302+
303+
$this->assertArrayHasKey('url', $output['items'][0]['properties']);
304+
$this->assertEquals('https://example.com/relative.html', $output['items'][0]['properties']['url'][0]);
305+
}
306+
299307
}

0 commit comments

Comments
 (0)