Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit d3a2e33

Browse files
committed
protocol parsing (#516)
1 parent ad8ca7d commit d3a2e33

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

core/resolve.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { isNode } from './common.js';
66
function throwResolveError (relUrl, parentUrl) {
77
throw new RangeError('Unable to resolve "' + relUrl + '" to ' + parentUrl);
88
}
9+
var protocolRegEx = /^[^/]+:/;
910
export function resolveIfNotPlain (relUrl, parentUrl) {
1011
relUrl = relUrl.trim();
11-
var parentProtocol = parentUrl && parentUrl.substr(0, parentUrl.indexOf(':') + 1);
12+
if (parentUrl)
13+
var parentProtocol = parentUrl.match(protocolRegEx);
1214

1315
var firstChar = relUrl[0];
1416
var secondChar = relUrl[1];
@@ -17,12 +19,12 @@ export function resolveIfNotPlain (relUrl, parentUrl) {
1719
if (firstChar === '/' && secondChar === '/') {
1820
if (!parentProtocol)
1921
throwResolveError(relUrl, parentUrl);
20-
return parentProtocol + relUrl;
22+
return parentProtocol[0] + relUrl;
2123
}
2224
// relative-url
2325
else if (firstChar === '.' && (secondChar === '/' || secondChar === '.' && (relUrl[2] === '/' || relUrl.length === 2) || relUrl.length === 1)
2426
|| firstChar === '/') {
25-
var parentIsPlain = !parentProtocol || parentUrl[parentProtocol.length] !== '/';
27+
var parentIsPlain = !parentProtocol || parentUrl[parentProtocol[0].length] !== '/';
2628

2729
// read pathname from parent if a URL
2830
// pathname taken to be part after leading "/"
@@ -33,10 +35,10 @@ export function resolveIfNotPlain (relUrl, parentUrl) {
3335
throwResolveError(relUrl, parentUrl);
3436
pathname = parentUrl;
3537
}
36-
else if (parentUrl[parentProtocol.length + 1] === '/') {
38+
else if (parentUrl[parentProtocol[0].length + 1] === '/') {
3739
// resolving to a :// so we need to read out the auth and host
38-
if (parentProtocol !== 'file:') {
39-
pathname = parentUrl.substr(parentProtocol.length + 2);
40+
if (parentProtocol[0] !== 'file:') {
41+
pathname = parentUrl.substr(parentProtocol[0].length + 2);
4042
pathname = pathname.substr(pathname.indexOf('/') + 1);
4143
}
4244
else {
@@ -45,7 +47,7 @@ export function resolveIfNotPlain (relUrl, parentUrl) {
4547
}
4648
else {
4749
// resolving to :/ so pathname is the /... part
48-
pathname = parentUrl.substr(parentProtocol.length + 1);
50+
pathname = parentUrl.substr(parentProtocol[0].length + 1);
4951
}
5052

5153
if (firstChar === '/') {

0 commit comments

Comments
 (0)