jfromaniello/url-join

Joining with absolute URLs

Closed this issue · 2 comments

When joining two absolute URLs, the output string seems to be incorrect:

join('https://foobar.com/barbaz/', 'https://quux.com/norf') === 'https://foobar.com/barbaz/https://quux.com/norf'

I would expect fragments that are absolute URLs to replace everything that was previously provided (becomes the new base URL):

join('https://foobar.com/barbaz/', 'https://quux.com/norf') === 'https://quux.com/norf'
join('https://foobar.com/barbaz/', 'quuxnorf', '//waldo) === 'https://waldo'

You could try the built-in URL class:

> new URL('https://quux.com/norf', 'https://foobar.com/barbaz/').toString()
'https://quux.com/norf'
> new URL('//waldo', 'https://foobar.com/barbaz/').toString()
'https://waldo/'

This is out of scope for the functionality of this package, you must provide valid parts of a single URL. I'd agree with @mic159 that the URL API here is a better fit.