forked from friendica/php-json-ld
Disallow keywords in property generator, allow alias in context.
This commit is contained in:
parent
d7bb4b3cba
commit
5466070d7d
27
jsonld.php
27
jsonld.php
|
@ -4069,6 +4069,11 @@ class JsonLdProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_string($value)) {
|
if(is_string($value)) {
|
||||||
|
// expand value to a full IRI
|
||||||
|
$id = $this->_expandIri(
|
||||||
|
$active_ctx, $value, array('vocab' => true, 'base' => true),
|
||||||
|
$local_ctx, $defined);
|
||||||
|
|
||||||
if(self::_isKeyword($value)) {
|
if(self::_isKeyword($value)) {
|
||||||
// disallow aliasing @context and @preserve
|
// disallow aliasing @context and @preserve
|
||||||
if($value === '@context' || $value === '@preserve') {
|
if($value === '@context' || $value === '@preserve') {
|
||||||
|
@ -4084,15 +4089,10 @@ class JsonLdProcessor {
|
||||||
array($this, '_compareShortestLeast'));
|
array($this, '_compareShortestLeast'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// expand value to a full IRI
|
|
||||||
$value = $this->_expandIri(
|
|
||||||
$active_ctx, $value, array('base' => true), $local_ctx, $defined);
|
|
||||||
}
|
|
||||||
|
|
||||||
// define/redefine term to expanded IRI/keyword
|
// define/redefine term to expanded IRI/keyword
|
||||||
$active_ctx->mappings->{$term} = (object)array(
|
$active_ctx->mappings->{$term} = (object)array(
|
||||||
'@id' => $value, 'propertyGenerator' => false);
|
'@id' => $id, 'propertyGenerator' => false);
|
||||||
$defined->{$term} = true;
|
$defined->{$term} = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4123,16 +4123,20 @@ class JsonLdProcessor {
|
||||||
$property_generator = array();
|
$property_generator = array();
|
||||||
$ids = $id;
|
$ids = $id;
|
||||||
foreach($ids as $id) {
|
foreach($ids as $id) {
|
||||||
if(!is_string($id) || $id === '@type') {
|
// expand @id
|
||||||
|
if(is_string($id)) {
|
||||||
|
$id = $this->_expandIri(
|
||||||
|
$active_ctx, $id, array('vocab' => true, 'base' => true),
|
||||||
|
$local_ctx, $defined);
|
||||||
|
}
|
||||||
|
if(!is_string($id) || self::_isKeyword($id)) {
|
||||||
throw new JsonLdException(
|
throw new JsonLdException(
|
||||||
'Invalid JSON-LD syntax; property generators must consist of ' .
|
'Invalid JSON-LD syntax; property generators must consist of ' .
|
||||||
'an @id array containing only strings and no string can be ' .
|
'an @id array containing only strings and no string can be ' .
|
||||||
'"@type".',
|
'"@type".',
|
||||||
'jsonld.SyntaxError', array('context' => $local_ctx));
|
'jsonld.SyntaxError', array('context' => $local_ctx));
|
||||||
}
|
}
|
||||||
// expand @id
|
$property_generator[] = $id;
|
||||||
$property_generator[] = $this->_expandIri(
|
|
||||||
$active_ctx, $id, array('base' => true), $local_ctx, $defined);
|
|
||||||
}
|
}
|
||||||
// add sorted property generator as @id in mapping
|
// add sorted property generator as @id in mapping
|
||||||
sort($property_generator);
|
sort($property_generator);
|
||||||
|
@ -4148,7 +4152,8 @@ class JsonLdProcessor {
|
||||||
else {
|
else {
|
||||||
// add @id to mapping
|
// add @id to mapping
|
||||||
$mapping->{'@id'} = $this->_expandIri(
|
$mapping->{'@id'} = $this->_expandIri(
|
||||||
$active_ctx, $id, array('base' => true), $local_ctx, $defined);
|
$active_ctx, $id, array('vocab' => true, 'base' => true),
|
||||||
|
$local_ctx, $defined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue