Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Mon, 23 Apr 2012 15:36:06 -0400
changeset 564 56087134ddc6
parent 563 52c8ffbae3d2
child 565 7a00404b2d46
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Sun Apr 22 20:26:51 2012 -0400
+++ b/playground/jsonld.js	Mon Apr 23 15:36:06 2012 -0400
@@ -136,6 +136,11 @@
       compacted = [compacted];
     }
 
+    // follow @context key
+    if(_isObject(ctx) && '@context' in ctx) {
+      ctx = ctx['@context'];
+    }
+
     // build output context
     ctx = _clone(ctx);
     if(!_isArray(ctx)) {
@@ -3385,6 +3390,7 @@
     else if(_isObject(input)) {
       for(var key in input) {
         if(key !== '@context') {
+          findUrls(input[key], replace);
           continue;
         }
 
@@ -3400,7 +3406,7 @@
                 ctx[i] = urls[ctx[i]];
               }
               // unresolved @context found
-              else {
+              else if(!(ctx[i] in urls)) {
                 urls[ctx[i]] = {};
               }
             }
@@ -3413,7 +3419,7 @@
             input[key] = urls[ctx];
           }
           // unresolved @context found
-          else {
+          else if(!(ctx in urls)) {
             urls[ctx] = {};
           }
         }
@@ -3480,7 +3486,8 @@
         errors.push(err);
       }
       else {
-        // FIXME: needs to recurse to resolve URLs in the result
+        // FIXME: needs to recurse to resolve URLs in the result, and
+        // detect cycles, and limit recursion
         urls[url] = ctx['@context'] || {};
       }