Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

URL: Fix resolving from non-file to file URLs. #14146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ Url.prototype.resolveObject = function(relative) {
}

result.protocol = relative.protocol;
if (!relative.host && !hostlessProtocol[relative.protocol]) {
if (!relative.host &&
!/file:?/.test(relative.protocol) &&
!hostlessProtocol[relative.protocol]) {
var relPath = (relative.pathname || '').split('/');
while (relPath.length && !(relative.host = relPath.shift()));
if (!relative.host) relative.host = '';
Expand Down
4 changes: 3 additions & 1 deletion test/simple/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,9 @@ var relativeTests = [
['http://example.com/b//c//d;p?q#blarg',
'http:/a/b/c/d',
'http://example.com/a/b/c/d'],
['/foo/bar/baz', '/../etc/passwd', '/etc/passwd']
['/foo/bar/baz', '/../etc/passwd', '/etc/passwd'],
['http://localhost', 'file:///Users/foo', 'file:///Users/foo'],
['http://localhost', 'file://foo/Users', 'file://foo/Users']
];
relativeTests.forEach(function(relativeTest) {
var a = url.resolve(relativeTest[0], relativeTest[1]),
Expand Down