forked from friendica/php-json-ld
Do not remove relative '../' with empty base.
This commit is contained in:
parent
24fa461705
commit
baa3cdf2f6
45
jsonld.php
45
jsonld.php
|
@ -403,29 +403,32 @@ function jsonld_prepend_base($base, $iri) {
|
||||||
};
|
};
|
||||||
$segments = array_values(array_filter($segments, $filter));
|
$segments = array_values(array_filter($segments, $filter));
|
||||||
|
|
||||||
// remove as many '..' as possible
|
// do not remove '..' for empty base
|
||||||
for($i = 0; $i < count($segments);) {
|
if($base['scheme'] !== '') {
|
||||||
$segment = $segments[$i];
|
// remove as many '..' as possible
|
||||||
if($segment === '..') {
|
for($i = 0; $i < count($segments);) {
|
||||||
// too many reverse dots
|
$segment = $segments[$i];
|
||||||
if($i === 0) {
|
if($segment === '..') {
|
||||||
$last = $segments[count($segments) - 1];
|
// too many reverse dots
|
||||||
if($last !== '..') {
|
if($i === 0) {
|
||||||
$segments = array($last);
|
$last = $segments[count($segments) - 1];
|
||||||
|
if($last !== '..') {
|
||||||
|
$segments = array($last);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$segments = array();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$segments = array();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove '..' and previous segment
|
// remove '..' and previous segment
|
||||||
array_splice($segments, $i - 1, 2);
|
array_splice($segments, $i - 1, 2);
|
||||||
$segments = array_values($segments);
|
$segments = array_values($segments);
|
||||||
$i -= 1;
|
$i -= 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$i += 1;
|
$i += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue