From 6ad92ee1d7ec7fb94d5f75fbce03b9f45ea9eeeb Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Wed, 6 Feb 2019 10:42:47 +0100 Subject: [PATCH] [fix] Return the base URL pathname when the relative URL is empty Fixes #157 --- index.js | 2 ++ test/test.js | 1 + 2 files changed, 3 insertions(+) diff --git a/index.js b/index.js index c616bfd..621b56d 100644 --- a/index.js +++ b/index.js @@ -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] diff --git a/test/test.js b/test/test.js index 4302d9a..3d64ae3 100644 --- a/test/test.js +++ b/test/test.js @@ -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'],