Do not remove relative '../' with empty base.

This commit is contained in:
Dave Longley 2013-02-28 16:50:43 -05:00
parent 24fa461705
commit baa3cdf2f6

View file

@ -394,38 +394,41 @@ function jsonld_prepend_base($base, $iri) {
$segments = explode('/', $path);
// remove '.' and '' (do not remove trailing empty path)
$idx = -1;
$end = count($segments) - 1;
$filter = function($e) use (&$idx, $end) {
$idx += 1;
return $e !== '.' && ($e !== '' || $idx === $end);
};
$segments = array_values(array_filter($segments, $filter));
// remove '.' and '' (do not remove trailing empty path)
$idx = -1;
$end = count($segments) - 1;
$filter = function($e) use (&$idx, $end) {
$idx += 1;
return $e !== '.' && ($e !== '' || $idx === $end);
};
$segments = array_values(array_filter($segments, $filter));
// remove as many '..' as possible
for($i = 0; $i < count($segments);) {
$segment = $segments[$i];
if($segment === '..') {
// too many reverse dots
if($i === 0) {
$last = $segments[count($segments) - 1];
if($last !== '..') {
$segments = array($last);
// do not remove '..' for empty base
if($base['scheme'] !== '') {
// remove as many '..' as possible
for($i = 0; $i < count($segments);) {
$segment = $segments[$i];
if($segment === '..') {
// too many reverse dots
if($i === 0) {
$last = $segments[count($segments) - 1];
if($last !== '..') {
$segments = array($last);
}
else {
$segments = array();
}
break;
}
else {
$segments = array();
}
break;
// remove '..' and previous segment
array_splice($segments, $i - 1, 2);
$segments = array_values($segments);
$i -= 1;
}
else {
$i += 1;
}
// remove '..' and previous segment
array_splice($segments, $i - 1, 2);
$segments = array_values($segments);
$i -= 1;
}
else {
$i += 1;
}
}