From 89d90fbae24d42cb9d2975921daa607cbb586ffd Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Wed, 9 Jul 2014 15:16:24 -0400 Subject: [PATCH] Fix context caching bug. - Update active context for each processed context to ensure the proper associations are made in the cache between an active context, the local context processed, and the result. --- jsonld.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/jsonld.php b/jsonld.php index 454affd..c3454a2 100644 --- a/jsonld.php +++ b/jsonld.php @@ -2982,14 +2982,13 @@ class JsonLdProcessor { return self::_cloneActiveContext($active_ctx); } - // process each context in order + // process each context in order, update active context + // on each iteration to ensure proper caching $rval = $active_ctx; - $must_clone = true; foreach($ctxs as $ctx) { // reset to initial context if($ctx === null) { - $rval = $this->_getInitialContext($options); - $must_clone = false; + $rval = $active_ctx = $this->_getInitialContext($options); continue; } @@ -3010,17 +3009,15 @@ class JsonLdProcessor { if(property_exists($jsonld_cache, 'activeCtx')) { $cached = $jsonld_cache->activeCtx->get($active_ctx, $ctx); if($cached) { - $rval = $cached; + $rval = $active_ctx = $cached; $must_clone = true; continue; } } - // clone context, if required, before updating - if($must_clone) { - $rval = self::_cloneActiveContext($rval); - $must_clone = false; - } + // update active context and clone new one before updating + $active_ctx = $rval; + $rval = self::_cloneActiveContext($rval); // define context mappings for keys in local context $defined = new stdClass(); @@ -4698,7 +4695,7 @@ class JsonLdProcessor { throw new JsonLdException( 'Invalid JSON-LD syntax; keywords cannot be overridden.', 'jsonld.SyntaxError', 'keyword redefinition', - array('context' => $local_ctx)); + array('context' => $local_ctx, 'term' => $term)); } // remove old mapping