Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit c18ec09

Browse filesBrowse files
committed
ensure backslash conversion on all paths
1 parent d35348d commit c18ec09
Copy full SHA for c18ec09

File tree

Expand file treeCollapse file tree

2 files changed

+11
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-2
lines changed
Open diff view settings
Collapse file

‎core/resolve.js‎

Copy file name to clipboardExpand all lines: core/resolve.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { isNode } from './common.js';
66
function throwResolveError (relUrl, parentUrl) {
77
throw new RangeError('Unable to resolve "' + relUrl + '" to ' + parentUrl);
88
}
9+
var backslashRegEx = /\\/g;
910
export 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
}
Collapse file

‎test/1-url-resolution.js‎

Copy file name to clipboardExpand all lines: test/1-url-resolution.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ describe('Simple normalization tests', function () {
88
it('Should resolve relative with protocol', function () {
99
assert.equal(resolveIfNotPlain('./x:y', 'https://x.com/y'), 'https://x.com/x:y');
1010
});
11+
it('Should convert \ into /', function () {
12+
assert.equal(resolveIfNotPlain('./a\\b', 'https://x.com/z'), 'https://x.com/a/b')
13+
});
1114
it('Should resolve windows paths as file:/// URLs', function () {
1215
assert.equal(resolveIfNotPlain('c:\\some\\path', 'file:///c:/adsf/asdf'), 'file:///c:/some/path');
1316
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.