Skip to content

Commit

Permalink
Fixing combineURLs, allowing single slash relatives
Browse files Browse the repository at this point in the history
  • Loading branch information
loklaan committed Dec 8, 2016
1 parent 2bd48d4 commit 75965ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/helpers/combineURLs.js
Expand Up @@ -8,8 +8,7 @@
* @returns {string} The combined URL
*/
module.exports = function combineURLs(baseURL, relativeURL) {
var end = relativeURL.replace(/^\/+/, '');
return end
? baseURL.replace(/\/+$/, '') + '/' + end
return relativeURL
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
: baseURL;
};
4 changes: 4 additions & 0 deletions test/specs/helpers/combineURLs.spec.js
Expand Up @@ -16,4 +16,8 @@ describe('helpers::combineURLs', function () {
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/');
});
});

0 comments on commit 75965ff

Please sign in to comment.