Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Tue, 05 Mar 2013 18:28:00 -0500
changeset 1376 9654192b6c2d
parent 1375 62c32b280fcc
child 1377 79cb9bbf75ce
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Tue Mar 05 17:31:58 2013 -0500
+++ b/playground/jsonld.js	Tue Mar 05 18:28:00 2013 -0500
@@ -6152,7 +6152,7 @@
   // MIT License
   var parseUri = {};
   parseUri.options = {
-    key: ['href','protocol','host','userInfo','user','password','hostname','port','relative','path','directory','file','query','hash'],
+    key: ['href','protocol','host','auth','user','password','hostname','port','relative','path','directory','file','query','hash'],
     parser: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)[email protected])?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/
   };
   jsonld.url.parse = function(str) {
@@ -6173,7 +6173,9 @@
     if(uri.query) {
       uri.path = uri.path + '?' + uri.query;
     }
-    uri.protocol += ':';
+    if(uri.protocol) {
+      uri.protocol += ':';
+    }
     if(uri.hash) {
       uri.hash = '#' + uri.hash;
     }
@@ -6187,17 +6189,27 @@
  * @param parsed the pre-parsed URL.
  */
 function _parseAuthority(parsed) {
-  // parse authority for network-path reference
-  if(parsed.href.indexOf('//') === 0) {
-    parsed.pathname = parsed.pathname.substr(2);
-    var idx = parsed.pathname.indexOf('/');
-    if(idx === -1) {
-      parsed.authority = parsed.pathname;
-      parsed.pathname = '';
-    }
+  // 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;
+      }
+    }
+    // must parse authority from pathname
     else {
-      parsed.authority = parsed.pathname.substr(0, idx);
-      parsed.pathname = parsed.pathname.substr(idx);
+      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);
+      }
     }
   }
   else {