Skip to content

Commit

Permalink
Handle query params with all delimiters (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops authored Oct 29, 2023
1 parent aca5adb commit 6712f54
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 @@ -49,8 +49,8 @@ function normalize (strArray) {
// remove trailing slash before parameters or hash
str = str.replace(/\/(\?|&|#[^!])/g, '$1');

// replace ? in parameters with &
const parts = str.split('?');
// replace ? and & in parameters with &
const 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', () => {

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', () => {
Expand Down

0 comments on commit 6712f54

Please sign in to comment.