Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Wed, 06 Mar 2013 11:37:59 -0500
changeset 1380 b5462e33f298
parent 1379 363c5e2eca20
child 1381 9bdb9eafb545
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Wed Mar 06 16:45:51 2013 +0100
+++ b/playground/jsonld.js	Wed Mar 06 11:37:59 2013 -0500
@@ -4486,7 +4486,7 @@
     // append relative path to the end of the last directory from base
     if(rel.pathname !== '') {
       path = path.substr(0, path.lastIndexOf('/') + 1);
-      if(path.length > 0 && path.lastIndexOf('/') !== path.length - 1) {
+      if(path.length > 0 && path.substr(-1) !== '/') {
         path += '/';
       }
       path += rel.pathname;
@@ -4531,7 +4531,7 @@
   if(base.href !== '') {
     root += (base.protocol || '') + '//' + base.authority;
   }
-  // scheme-relative root with empty base
+  // support network-path reference with empty base
   else if(iri.indexOf('//')) {
     root += '//';
   }
@@ -4560,8 +4560,7 @@
   var rval = '';
   if(baseSegments.length > 0) {
     // do not count the last segment if it isn't a path (doesn't end in '/')
-    if(base.normalizedPath.indexOf(
-      '/', base.normalizedPath.length - 1) === -1) {
+    if(base.normalizedPath.substr(-1) !== '/') {
       baseSegments.pop();
     }
     for(var i = 0; i < baseSegments.length; ++i) {
@@ -6189,36 +6188,27 @@
  * @param parsed the pre-parsed URL.
  */
 function _parseAuthority(parsed) {
-  // parse authority for relative network-path reference
-  if(parsed.href.indexOf(':') === -1 && parsed.href.indexOf('//') === 0) {
-    // authority already parsed, pathname should also be correct
-    if(parsed.host) {
-      parsed.authority = parsed.host;
-      if(parsed.auth) {
-        parsed.authority = parsed.auth + '@' + parsed.authority;
-      }
-    }
+  // parse authority for unparsed relative network-path reference
+  if(parsed.href.indexOf(':') === -1 && parsed.href.indexOf('//') === 0 &&
+    !parsed.host) {
     // must parse authority from pathname
+    parsed.pathname = parsed.pathname.substr(2);
+    var idx = parsed.pathname.indexOf('/');
+    if(idx === -1) {
+      parsed.authority = parsed.pathname;
+      parsed.pathname = '';
+    }
     else {
-      parsed.pathname = parsed.pathname.substr(2);
-      var idx = parsed.pathname.indexOf('/');
-      if(idx === -1) {
-        parsed.authority = parsed.pathname;
-        parsed.pathname = '';
-      }
-      else {
-        parsed.authority = parsed.pathname.substr(0, idx);
-        parsed.pathname = parsed.pathname.substr(idx);
-      }
+      parsed.authority = parsed.pathname.substr(0, idx);
+      parsed.pathname = parsed.pathname.substr(idx);
     }
   }
   else {
     // construct authority
-    parsed.authority = '';
+    parsed.authority = parsed.host || '';
     if(parsed.auth) {
-      parsed.authority += parsed.auth + '@';
-    }
-    parsed.authority += (parsed.host || '');
+      parsed.authority = parsed.auth + '@' + parsed.authority;
+    }
   }
 }