Skip to content

Commit

Permalink
[fix] Return the base URL pathname when the relative URL is empty (#166)
Browse files Browse the repository at this point in the history
Fixes #157
  • Loading branch information
lpinca committed Feb 19, 2019
1 parent 219b4c5 commit 52b9206
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function extractProtocol(address) {
* @private
*/
function resolve(relative, base) {
if (relative === '') return base;

var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
, i = path.length
, last = path[i - 1]
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ describe('url-parse', function () {
var tests = [
['', 'http://foo.com', ''],
['', 'http://foo.com/', '/'],
['', 'http://foo.com/a', '/a'],
['a', 'http://foo.com', '/a'],
['a/', 'http://foo.com', '/a/'],
['b/c', 'http://foo.com/a', '/b/c'],
Expand Down

0 comments on commit 52b9206

Please sign in to comment.