Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing combineURLs to support an empty relativeURL #581

Merged
merged 2 commits into from Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/helpers/combineURLs.js
Expand Up @@ -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;
};
8 changes: 8 additions & 0 deletions test/specs/helpers/combineURLs.spec.js
Expand Up @@ -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/');
});
});