jfromaniello/url-join

Incorrectly joins parts if there is a trailing question mark

ismay opened this issue · 4 comments

ismay commented

The code example below is not how I'd expect url-join to work:

var urlJoin = require("url-join")

// Results in "https://www.url.org/sub?/dryRun=true"
urlJoin("https://www.url.org", "/sub?", "dryRun=true") 

I'd expect: "https://www.url.org/sub?dryRun=true". So I'd not expect a slash to be prepended to the part following the questionmark.

why would you do that?
put the ? at the start of the querystring section and it works fine.

urlJoin("https://www.url.org", "/sub", "?dryRun=true")

Fun fact: if you have multiple ? after the first one, they get converted to &

ismay commented

why would you do that? put the ? at the start of the querystring section and it works fine.

Why not? I'd expect it to be in the docs that there are limitations to where the ? can appear in the supplied strings.

ismay commented

Fun fact: if you have multiple ? after the first one, they get converted to 7

Depends on your perspective. For a project with 2 million weekly downloads it'd be nice to not have those kinds of unpredictable results.

Looks like the same limitation applies to hashes, I will see if I can create a fix for this:

test('joins broken up query params', () => {
  assert.equal(
    urlJoin('http://example.com', '/foo/bar#', 'some-hash'),
    'http://example.com/foo/bar#some-hash'
  );
});