@@ -6,8 +6,10 @@ import { isNode } from './common.js';
66function throwResolveError ( relUrl , parentUrl ) {
77 throw new RangeError ( 'Unable to resolve "' + relUrl + '" to ' + parentUrl ) ;
88}
9+ var backslashRegEx = / \\ / g;
910export function resolveIfNotPlain ( relUrl , parentUrl ) {
10- relUrl = relUrl . trim ( ) ;
11+ if ( relUrl [ 0 ] === ' ' || relUrl [ relUrl . length - 1 ] === ' ' )
12+ relUrl = relUrl . trim ( ) ;
1113 var parentProtocol = parentUrl && parentUrl . substr ( 0 , parentUrl . indexOf ( ':' ) + 1 ) ;
1214
1315 var firstChar = relUrl [ 0 ] ;
@@ -17,12 +19,16 @@ export function resolveIfNotPlain (relUrl, parentUrl) {
1719 if ( firstChar === '/' && secondChar === '/' ) {
1820 if ( ! parentProtocol )
1921 throwResolveError ( relUrl , parentUrl ) ;
22+ if ( relUrl . indexOf ( '\\' ) !== - 1 )
23+ relUrl = relUrl . replace ( backslashRegEx , '/' ) ;
2024 return parentProtocol + relUrl ;
2125 }
2226 // relative-url
2327 else if ( firstChar === '.' && ( secondChar === '/' || secondChar === '.' && ( relUrl [ 2 ] === '/' || relUrl . length === 2 && ( relUrl += '/' ) ) ||
2428 relUrl . length === 1 && ( relUrl += '/' ) ) ||
2529 firstChar === '/' ) {
30+ if ( relUrl . indexOf ( '\\' ) !== - 1 )
31+ relUrl = relUrl . replace ( backslashRegEx , '/' ) ;
2632 var parentIsPlain = ! parentProtocol || parentUrl [ parentProtocol . length ] !== '/' ;
2733
2834 // read pathname from parent if a URL
@@ -115,7 +121,7 @@ export function resolveIfNotPlain (relUrl, parentUrl) {
115121 if ( isNode ) {
116122 // C:\x becomes file:///c:/x (we don't support C|\x)
117123 if ( relUrl [ 1 ] === ':' && relUrl [ 2 ] === '\\' && relUrl [ 0 ] . match ( / [ a - z ] / i) )
118- return 'file:///' + relUrl . replace ( / \\ / g , '/' ) ;
124+ return 'file:///' + relUrl . replace ( backslashRegEx , '/' ) ;
119125 }
120126 return relUrl ;
121127 }
0 commit comments