Do not change IRIs if base is empty.

This commit is contained in:
Dave Longley 2013-02-28 17:10:21 -05:00
parent e112743436
commit 5847ac58b1

View file

@ -1,7 +1,7 @@
<?php
/**
* PHP implementation of the JSON-LD API.
* Version: 0.0.11
* Version: 0.0.12
*
* @author Dave Longley
*
@ -360,15 +360,23 @@ function jsonld_prepend_base($base, $iri) {
return $iri;
}
// parse base if it is a string
if(is_string($base)) {
$base = jsonld_parse_url($base);
}
// if base is empty, do not change iri
if($base['scheme'] === '') {
return $iri;
}
$authority = $base['host'];
if(isset($base['port'])) {
$authority .= ":{$base['port']}";
}
$rel = jsonld_parse_url($iri);
// per RFC3986 normalize slashes and dots in path
// IRI contains authority
@ -403,8 +411,6 @@ function jsonld_prepend_base($base, $iri) {
};
$segments = array_values(array_filter($segments, $filter));
// do not remove '..' for empty base
if($base['scheme'] !== '') {
// remove as many '..' as possible
for($i = 0; $i < count($segments);) {
$segment = $segments[$i];
@ -430,7 +436,6 @@ function jsonld_prepend_base($base, $iri) {
$i += 1;
}
}
}
$path = implode('/', $segments);
@ -442,20 +447,11 @@ function jsonld_prepend_base($base, $iri) {
$path .= "#{$rel['fragment']}";
}
$absolute_iri = '';
if($base['scheme'] === '') {
if(strpos($iri, '//') === 0) {
$absolute_iri .= '//';
}
$absolute_iri .= $path;
}
else {
$absolute_iri .= "{$base['scheme']}://";
$absolute_iri = "{$base['scheme']}://";
if(isset($base['auth'])) {
$absolute_iri .= "{$base['auth']}@";
}
$absolute_iri .= "$authority/$path";
}
return $absolute_iri;
}