This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Monkey patching the Node URL module to avoid a bug with URL resolution. | ||
// See https://github.com/joyent/node/pull/14146 | ||
const URL = require('url'); | ||
|
||
|
||
exports.parse = URL.parse; | ||
exports.format = URL.format; | ||
|
||
exports.resolve = function (from, to) { | ||
// The `to` parameter is ofter a pre-parsed URL object. Need to make a | ||
// defensive copy to avoid the `host` assignment bug. | ||
var original = URL.parse(URL.format(to)); | ||
var resolved = URL.parse(URL.resolve(from, to)); | ||
|
||
if (/file:?/.test(original.protocol) && !original.host && resolved.host) { | ||
return URL.format(original); | ||
} | ||
|
||
return URL.format(resolved); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const assert = require('assert'); | ||
const NativeURL = require('url'); | ||
const ZombieURL = require('../src/url'); | ||
|
||
|
||
describe('URL', function() { | ||
describe('resolve', function() { | ||
const patterns = [ | ||
['http://localhost', 'foo', 'http://localhost/foo'], | ||
['http://localhost/foo/bar', 'baz', 'http://localhost/foo/baz'], | ||
['http://localhost/foo/bar', '/bar', 'http://localhost/bar'], | ||
['http://localhost', 'file://foo/Users', 'file://foo/Users'], | ||
['http://localhost', 'file:///Users/foo', 'file:///Users/foo'] | ||
]; | ||
|
||
it('is not the native resolve implementation', function() { | ||
assert.notStrictEqual(ZombieURL.resolve, NativeURL.resolve); | ||
}); | ||
|
||
it('resolves URLs correctly', function() { | ||
patterns.forEach(function (pattern) { | ||
assert.equal(ZombieURL.resolve(pattern[0], pattern[1]), pattern[2]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('parse', function() { | ||
it('is the native parse implementation', function() { | ||
assert.strictEqual(ZombieURL.parse, NativeURL.parse); | ||
}); | ||
}); | ||
|
||
describe('format', function() { | ||
it('is the native format implementation', function() { | ||
assert.strictEqual(ZombieURL.format, NativeURL.format); | ||
}); | ||
}); | ||
}); |