@@ -4486,7 +4486,7 @@ function _prependBase(base, iri) {
4486
4486
// append relative path to the end of the last directory from base
4487
4487
if ( rel . pathname !== '' ) {
4488
4488
path = path . substr ( 0 , path . lastIndexOf ( '/' ) + 1 ) ;
4489
- if ( path . length > 0 && path . lastIndexOf ( '/' ) !== path . length - 1 ) {
4489
+ if ( path . length > 0 && path . substr ( - 1 ) !== '/' ) {
4490
4490
path += '/' ;
4491
4491
}
4492
4492
path += rel . pathname ;
@@ -4531,7 +4531,7 @@ function _removeBase(base, iri) {
4531
4531
if ( base . href !== '' ) {
4532
4532
root += ( base . protocol || '' ) + '//' + base . authority ;
4533
4533
}
4534
- // scheme-relative root with empty base
4534
+ // support network-path reference with empty base
4535
4535
else if ( iri . indexOf ( '//' ) ) {
4536
4536
root += '//' ;
4537
4537
}
@@ -4560,8 +4560,7 @@ function _removeBase(base, iri) {
4560
4560
var rval = '' ;
4561
4561
if ( baseSegments . length > 0 ) {
4562
4562
// do not count the last segment if it isn't a path (doesn't end in '/')
4563
- if ( base . normalizedPath . indexOf (
4564
- '/' , base . normalizedPath . length - 1 ) === - 1 ) {
4563
+ if ( base . normalizedPath . substr ( - 1 ) !== '/' ) {
4565
4564
baseSegments . pop ( ) ;
4566
4565
}
4567
4566
for ( var i = 0 ; i < baseSegments . length ; ++ i ) {
@@ -6189,36 +6188,27 @@ else {
6189
6188
* @param parsed the pre-parsed URL.
6190
6189
*/
6191
6190
function _parseAuthority ( parsed ) {
6192
- // parse authority for relative network-path reference
6193
- if ( parsed . href . indexOf ( ':' ) === - 1 && parsed . href . indexOf ( '//' ) === 0 ) {
6194
- // authority already parsed, pathname should also be correct
6195
- if ( parsed . host ) {
6196
- parsed . authority = parsed . host ;
6197
- if ( parsed . auth ) {
6198
- parsed . authority = parsed . auth + '@' + parsed . authority ;
6199
- }
6200
- }
6191
+ // parse authority for unparsed relative network-path reference
6192
+ if ( parsed . href . indexOf ( ':' ) === - 1 && parsed . href . indexOf ( '//' ) === 0 &&
6193
+ ! parsed . host ) {
6201
6194
// must parse authority from pathname
6195
+ parsed . pathname = parsed . pathname . substr ( 2 ) ;
6196
+ var idx = parsed . pathname . indexOf ( '/' ) ;
6197
+ if ( idx === - 1 ) {
6198
+ parsed . authority = parsed . pathname ;
6199
+ parsed . pathname = '' ;
6200
+ }
6202
6201
else {
6203
- parsed . pathname = parsed . pathname . substr ( 2 ) ;
6204
- var idx = parsed . pathname . indexOf ( '/' ) ;
6205
- if ( idx === - 1 ) {
6206
- parsed . authority = parsed . pathname ;
6207
- parsed . pathname = '' ;
6208
- }
6209
- else {
6210
- parsed . authority = parsed . pathname . substr ( 0 , idx ) ;
6211
- parsed . pathname = parsed . pathname . substr ( idx ) ;
6212
- }
6202
+ parsed . authority = parsed . pathname . substr ( 0 , idx ) ;
6203
+ parsed . pathname = parsed . pathname . substr ( idx ) ;
6213
6204
}
6214
6205
}
6215
6206
else {
6216
6207
// construct authority
6217
- parsed . authority = '' ;
6208
+ parsed . authority = parsed . host || '' ;
6218
6209
if ( parsed . auth ) {
6219
- parsed . authority + = parsed . auth + '@' ;
6210
+ parsed . authority = parsed . auth + '@' + parsed . authority ;
6220
6211
}
6221
- parsed . authority += ( parsed . host || '' ) ;
6222
6212
}
6223
6213
}
6224
6214
0 commit comments