fix(buildUrl): relative url is invalid URL (OAS3) or non-url (OAS2) (#6864)
* OAS3: relative url when no servers defined AND specUrl is invalid Url * OAS2: specUrl is non-url string
This commit is contained in:
@@ -3,21 +3,25 @@ export function isAbsoluteUrl(url) {
|
||||
}
|
||||
|
||||
export function addProtocol(url) {
|
||||
if(!url.match(/^\/\//i)) return url // Checks if protocol is missing e.g. //example.com
|
||||
if (!url.match(/^\/\//i)) return url // Checks if protocol is missing e.g. //example.com
|
||||
|
||||
return `${window.location.protocol}${url}`
|
||||
}
|
||||
|
||||
export function buildBaseUrl(selectedServer, specUrl) {
|
||||
if(!selectedServer) return specUrl
|
||||
if(isAbsoluteUrl(selectedServer)) return addProtocol(selectedServer)
|
||||
|
||||
if (!selectedServer) return specUrl
|
||||
if (isAbsoluteUrl(selectedServer)) return addProtocol(selectedServer)
|
||||
|
||||
return new URL(selectedServer, specUrl).href
|
||||
}
|
||||
|
||||
export function buildUrl(url, specUrl, { selectedServer="" } = {}) {
|
||||
if(!url) return
|
||||
if(isAbsoluteUrl(url)) return url
|
||||
export function buildUrl(url, specUrl, { selectedServer="" } = {}) {
|
||||
if (!url) return
|
||||
if (isAbsoluteUrl(url)) return url
|
||||
|
||||
const baseUrl = buildBaseUrl(selectedServer, specUrl)
|
||||
if (!isAbsoluteUrl(baseUrl)) {
|
||||
return new URL(url, window.location.href).href
|
||||
}
|
||||
return new URL(url, baseUrl).href
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user