Fix bugs w/prepend base.
This commit is contained in:
parent
61e1140b3b
commit
612f56aa6c
20
jsonld.php
20
jsonld.php
|
@ -282,10 +282,18 @@ function jsonld_parse_url($url) {
|
||||||
* @return string the absolute IRI.
|
* @return string the absolute IRI.
|
||||||
*/
|
*/
|
||||||
function jsonld_prepend_base($base, $iri) {
|
function jsonld_prepend_base($base, $iri) {
|
||||||
|
// already an absolute IRI
|
||||||
|
if(strpos($iri, ':') !== false) {
|
||||||
|
return $iri;
|
||||||
|
}
|
||||||
|
|
||||||
if(is_string($base)) {
|
if(is_string($base)) {
|
||||||
$base = jsonld_parse_url($base);
|
$base = jsonld_parse_url($base);
|
||||||
}
|
}
|
||||||
$authority = $base['host'];
|
$authority = $base['host'];
|
||||||
|
if(isset($base['port'])) {
|
||||||
|
$authority .= ":{$base['port']}";
|
||||||
|
}
|
||||||
$rel = jsonld_parse_url($iri);
|
$rel = jsonld_parse_url($iri);
|
||||||
|
|
||||||
// per RFC3986 normalize slashes and dots in path
|
// per RFC3986 normalize slashes and dots in path
|
||||||
|
@ -352,13 +360,19 @@ function jsonld_prepend_base($base, $iri) {
|
||||||
|
|
||||||
// add query and hash
|
// add query and hash
|
||||||
if(isset($rel['query'])) {
|
if(isset($rel['query'])) {
|
||||||
$path .= '?' . $rel['query'];
|
$path .= "?{$rel['query']}";
|
||||||
}
|
}
|
||||||
if(isset($rel['fragment'])) {
|
if(isset($rel['fragment'])) {
|
||||||
$path .= '#' . $rel['fragment'];
|
$path .= "#{$rel['fragment']}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $base['scheme'] . "://$authority$path";
|
$absolute_iri = "{$base['scheme']}://";
|
||||||
|
if(isset($base['user']) || isset($base['pass'])) {
|
||||||
|
$absolute_iri .= "{$base['user']}:{$base['pass']}@";
|
||||||
|
}
|
||||||
|
$absolute_iri .= "$authority$path";
|
||||||
|
|
||||||
|
return $absolute_iri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue