Skip to content

Commit

Permalink
fixed query string handling, closes #9, closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
rauberdaniel committed Mar 25, 2016
1 parent 197bfe8 commit e190fe2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/url-join.js
Expand Up @@ -13,7 +13,10 @@
str = str.replace(/([^:\s])\/+/g, '$1/');

// remove trailing slash before parameters or hash
str = str.replace(/\/(\?|#)/g, '$1');
str = str.replace(/\/(\?|&|#)/g, '$1');

// replace ? in parameters with &
str = str.replace(/(\?.+)\?/g, '$1&');

return str;
}
Expand Down
8 changes: 8 additions & 0 deletions test/tests.js
Expand Up @@ -30,4 +30,12 @@ describe('url join', function () {
urljoin('//www.google.com', 'foo/bar', '?test=123')
.should.eql('//www.google.com/foo/bar?test=123')
});

it('should merge multiple query params properly', function () {
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456')
.should.eql('http://www.google.com/foo/bar?test=123&key=456');

urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?boom=value', '&key=456')
.should.eql('http://www.google.com/foo/bar?test=123&boom=value&key=456');
});
});

0 comments on commit e190fe2

Please sign in to comment.