Skip to content

Commit

Permalink
Handle query params with all delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops committed May 27, 2022
1 parent a1d70ce commit 704ff31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/url-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ function normalize (strArray) {
// remove trailing slash before parameters or hash
str = str.replace(/\/(\?|&|#[^!])/g, '$1');

// replace ? in parameters with &
var parts = str.split('?');
// replace ? and & in parameters with &
var parts = str.split(/(?:\?|&)+/);
str = parts.shift() + (parts.length > 0 ? '?': '') + parts.join('&');

return str;
Expand Down
6 changes: 6 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ describe('url join', function () {

urlJoin('http://example.org/x', '?a=1', '?b=2', '?c=3', '?d=4')
.should.eql('http://example.org/x?a=1&b=2&c=3&d=4');

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', '?key=456')
.should.eql('http://www.google.com/foo/bar?test=123&key=456');
});

it('should merge slashes in paths correctly', function () {
Expand Down

0 comments on commit 704ff31

Please sign in to comment.