Fix bugs with hashes and queries when compacting to relative IRIs.
This commit is contained in:
parent
f0746b22c0
commit
a3369ffb21
17
jsonld.php
17
jsonld.php
|
@ -478,9 +478,12 @@ function jsonld_remove_base($base, $iri) {
|
||||||
return $iri;
|
return $iri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove root from IRI
|
||||||
|
$rel = jsonld_parse_url(substr($iri, strlen($root)));
|
||||||
|
|
||||||
// remove path segments that match
|
// remove path segments that match
|
||||||
$base_segments = explode('/', $base['path']);
|
$base_segments = explode('/', $base['path']);
|
||||||
$iri_segments = explode('/', substr($iri, strlen($root)));
|
$iri_segments = explode('/', $rel['path']);
|
||||||
while(count($base_segments) > 0 && count($iri_segments) > 0) {
|
while(count($base_segments) > 0 && count($iri_segments) > 0) {
|
||||||
if($base_segments[0] !== $iri_segments[0]) {
|
if($base_segments[0] !== $iri_segments[0]) {
|
||||||
break;
|
break;
|
||||||
|
@ -504,6 +507,18 @@ function jsonld_remove_base($base, $iri) {
|
||||||
// prepend remaining segments
|
// prepend remaining segments
|
||||||
$rval .= implode('/', $iri_segments);
|
$rval .= implode('/', $iri_segments);
|
||||||
|
|
||||||
|
// add query and hash
|
||||||
|
if(isset($rel['query'])) {
|
||||||
|
$rval .= "?{$rel['query']}";
|
||||||
|
}
|
||||||
|
if(isset($rel['fragment'])) {
|
||||||
|
$rval .= "#{$rel['fragment']}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rval === '') {
|
||||||
|
$rval = './';
|
||||||
|
}
|
||||||
|
|
||||||
return $rval;
|
return $rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue