Skip to content

Commit

Permalink
Return absolute URLs unmodified when resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Apr 23, 2021
1 parent aea083b commit c64b32b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ export function resolveUrl (baseUrl, url) {
if (typeof baseUrl !== 'string') throw new Error('Base URL must be a string')
if (typeof url !== 'string') throw new Error('URL must be a string')

const urlParsed = urlParse(url)
if (urlParsed.host) return url

const baseUrlParsed = urlParse(baseUrl)

if (baseUrlParsed.host) return urlParse(url, baseUrl).toString()

const urlParsed = urlParse(url)
urlParsed.pathname = resolvePath(baseUrlParsed.pathname, urlParsed.pathname)

return urlParsed.toString()
Expand Down
1 change: 1 addition & 0 deletions test/suite/consumer/urls.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Consumer URL methods', () => {
expect(consumer.absoluteUrl('x/y')).toBe('https://iconduit.github.io/p/a/t/x/y')
expect(consumer.absoluteUrl('x/y/')).toBe('https://iconduit.github.io/p/a/t/x/y/')
expect(consumer.absoluteUrl('https://example.org/x/y')).toBe('https://example.org/x/y')
expect(consumer.absoluteUrl('iconduit://dashboard')).toBe('iconduit://dashboard')
})

it('should be able to resolve relative URLs', () => {
Expand Down

0 comments on commit c64b32b

Please sign in to comment.