Browse Source

Add base URL resolution

master
J. King 4 years ago
parent
commit
9fe1e1a575
  1. 4
      lib/Parser/XML/Construct.php
  2. 2
      lib/Parser/XML/Feed.php
  3. 13
      tests/cases/XML/feed-atom.yaml

4
lib/Parser/XML/Construct.php

@ -155,7 +155,7 @@ abstract class Construct {
}, $mediaTypes)))));
$rels = $this->fetchAtomRelations($rel, $context);
if ($rels && !$mediaTypes) {
return new Url($rels[0]->getAttribute("href"), );
return new Url($rels[0]->getAttribute("href"), $rels[0]->baseURI);
}
$result = array_reduce($rels, function($best, $cur) use ($mediaTypes) {
$t = trim($cur->getAttribute("type"));
@ -175,7 +175,7 @@ abstract class Construct {
}
return $best;
});
return $result ? new Url($result[0]->getAttribute("href")) : null;
return $result ? new Url($result[0]->getAttribute("href"), $result[0]->baseURI) : null;
}
/** Primitive to fetch an Atom feed/entry identifier */

2
lib/Parser/XML/Feed.php

@ -44,7 +44,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
if (!$this->document->loadXML($this->data, self::LIBXML_OPTIONS)) {
throw new Exception("notXML");
}
$this->document->documentURI = (string) $this->url;
$this->document->documentURI = $this->url;
$this->xpath = new XPath($this->document);
$this->subject = $this->document->documentElement;
$ns = $this->subject->namespaceURI;

13
tests/cases/XML/feed-atom.yaml

@ -163,3 +163,16 @@ Feed link 9: # The first matching relation wins
format: atom
version: '1.0'
link: 'http://example.com/'
Relative feed link:
doc_url: 'http://example.com/path/'
input: >
<feed xmlns="http://www.w3.org/2005/Atom">
<link href="/"/>
</feed>
output:
format: atom
version: '1.0'
meta:
url: 'http://example.com/path/'
link: ['/', 'http://example.com/path/']

Loading…
Cancel
Save