diff --git a/lib/helpers/combineURLs.js b/lib/helpers/combineURLs.js index 7145d10490..f1b58a5864 100644 --- a/lib/helpers/combineURLs.js +++ b/lib/helpers/combineURLs.js @@ -8,5 +8,7 @@ * @returns {string} The combined URL */ module.exports = function combineURLs(baseURL, relativeURL) { - return baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, ''); + return relativeURL + ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') + : baseURL; }; diff --git a/test/specs/helpers/combineURLs.spec.js b/test/specs/helpers/combineURLs.spec.js index e09b730bbd..2a427f5acd 100644 --- a/test/specs/helpers/combineURLs.spec.js +++ b/test/specs/helpers/combineURLs.spec.js @@ -12,4 +12,12 @@ describe('helpers::combineURLs', function () { it('should insert missing slash', function () { expect(combineURLs('https://api.github.com', 'users')).toBe('https://api.github.com/users'); }); + + it('should not insert slash when relative url missing/empty', function () { + expect(combineURLs('https://api.github.com/users', '')).toBe('https://api.github.com/users'); + }); + + it('should allow a single slash for relative url', function () { + expect(combineURLs('https://api.github.com/users', '/')).toBe('https://api.github.com/users/'); + }); });