From 7791361f1fa23dca7d9da115ba1f91f103126e96 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Tue, 7 Jan 2014 10:53:24 -0500 Subject: [PATCH] Skip IRI processing when base is null. --- jsonld.php | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/jsonld.php b/jsonld.php index 5cd60ac..7ecf93b 100644 --- a/jsonld.php +++ b/jsonld.php @@ -586,6 +586,11 @@ function jsonld_remove_dot_segments($path, $has_authority) { * @return string the absolute IRI. */ function jsonld_prepend_base($base, $iri) { + // skip IRI processing + if($base === null) { + return $iri; + } + // already an absolute IRI if(strpos($iri, ':') !== false) { return $iri; @@ -659,6 +664,11 @@ function jsonld_prepend_base($base, $iri) { * IRI. */ function jsonld_remove_base($base, $iri) { + // skip IRI processing + if($base === null) { + return $iri; + } + if(is_string($base)) { $base = jsonld_parse_url($base); } @@ -3069,7 +3079,10 @@ class JsonLdProcessor { '@context must be an absolute IRI or the empty string.', 'jsonld.SyntaxError', 'invalid base IRI', array('context' => $ctx)); } - $rval->{'@base'} = jsonld_parse_url($base); + if($base !== null) { + $base = jsonld_parse_url($base); + } + $rval->{'@base'} = $base; $defined->{'@base'} = true; } @@ -3285,6 +3298,9 @@ class JsonLdProcessor { sort($ids); foreach($ids as $id) { $node = $graph->{$id}; + if($id === '"') { + $id = ''; + } $properties = array_keys((array)$node); sort($properties); foreach($properties as $property) { @@ -3576,9 +3592,19 @@ class JsonLdProcessor { } $subjects = $graphs->{$graph}; if(!property_exists($subjects, $name)) { - $subjects->{$name} = new stdClass(); + if($name === '') { + $subjects->{'"'} = new stdClass(); + } + else { + $subjects->{$name} = new stdClass(); + } + } + if($name === '') { + $subject = $subjects->{'"'}; + } + else { + $subject = $subjects->{$name}; } - $subject = $subjects->{$name}; $subject->{'@id'} = $name; $properties = array_keys((array)$input); sort($properties); @@ -3602,6 +3628,9 @@ class JsonLdProcessor { $item_name = $namer->getName($item_name); } $this->_createNodeMap($item, $graphs, $graph, $namer, $item_name); + if($item_name === '') { + $item_name = '"'; + } self::addValue( $subjects->{$item_name}, $reverse_property, $referenced_node, array('propertyIsArray' => true, 'allowDuplicate' => false));