// protocol-relative URLs
if ( !this.protocol ) {
- this.protocol = defaultProtocol;
+ this.protocol = defaultUri.protocol;
+ }
+ // No host given:
+ if ( !this.host ) {
+ this.host = defaultUri.host;
+ // port ?
+ if ( !this.port ) {
+ this.port = defaultUri.port;
+ }
+ }
+ if ( this.path && this.path.charAt( 0 ) !== '/' ) {
+ // A real relative URL, relative to defaultUri.path. We can't really handle that since we cannot
+ // figure out whether the last path compoennt of defaultUri.path is a directory or a file.
+ throw new Error( 'Bad constructor arguments' );
}
-
if ( !( this.protocol && this.host && this.path ) ) {
throw new Error( 'Bad constructor arguments' );
}
}
};
- var defaultProtocol = ( new Uri( documentLocation ) ).protocol;
+ var defaultUri = new Uri( documentLocation );
return Uri;
};