From d14adbdf227cec1c6575ba36c94a35fee0fb4b0e Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Mon, 15 Apr 2013 11:09:06 -0400 Subject: [PATCH] Check invalid keyword aliasing via @id. --- jsonld.php | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/jsonld.php b/jsonld.php index d08aaca..db6ffe3 100644 --- a/jsonld.php +++ b/jsonld.php @@ -4395,26 +4395,9 @@ class JsonLdProcessor { return; } + // convert short-hand value to object w/@id 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)) { - // disallow aliasing @context and @preserve - if($value === '@context' || $value === '@preserve') { - throw new JsonLdException( - 'Invalid JSON-LD syntax; @context and @preserve cannot be aliased.', - 'jsonld.SyntaxError', array('context' => $local_ctx)); - } - } - - // define term to expanded IRI/keyword - $active_ctx->mappings->{$term} = (object)array( - '@id' => $id, 'reverse' => false); - $defined->{$term} = true; - return; + $value = (object)array('@id' => $value); } if(!is_object($value)) { @@ -4558,6 +4541,15 @@ class JsonLdProcessor { $mapping->{'@language'} = $language; } + + // disallow aliasing @context and @preserve + $id = $mapping->{'@id'}; + if($id === '@context' || $id === '@preserve') { + throw new JsonLdException( + 'Invalid JSON-LD syntax; @context and @preserve cannot be aliased.', + 'jsonld.SyntaxError', array('context' => $local_ctx)); + } + // define term mapping $active_ctx->mappings->{$term} = $mapping; $defined->{$term} = true;