diff --git a/lib/common-utils.ts b/lib/common-utils.ts index 671c2b751..8d4218b2d 100644 --- a/lib/common-utils.ts +++ b/lib/common-utils.ts @@ -71,22 +71,24 @@ export const determineFinalStatus = (statuses: TestStatus[]): TestStatus | null }; export const getUrlWithBase = (url: string | undefined, base: string | undefined): string => { + if (isEmpty(base)) { + return url ?? ''; + } + try { const userUrl = new URL(url ?? '', base); - // Manually overriding properties, because if url is absolute, the above won't work - if (!isEmpty(base)) { - const baseUrl = new URL(base as string); + // Manually overriding properties, because if userUrl is absolute, the above won't work + const baseUrl = new URL(base as string); - userUrl.host = baseUrl.host; - userUrl.protocol = baseUrl.protocol; - userUrl.port = baseUrl.port; - userUrl.username = baseUrl.username; - userUrl.password = baseUrl.password; + userUrl.host = baseUrl.host; + userUrl.protocol = baseUrl.protocol; + userUrl.port = baseUrl.port; + userUrl.username = baseUrl.username; + userUrl.password = baseUrl.password; - for (const [key, value] of baseUrl.searchParams) { - userUrl.searchParams.append(key, value); - } + for (const [key, value] of baseUrl.searchParams) { + userUrl.searchParams.append(key, value); } return userUrl.href; diff --git a/lib/static/components/icons/view-in-browser/index.jsx b/lib/static/components/icons/view-in-browser/index.jsx index 9f66bfd83..fca070abf 100644 --- a/lib/static/components/icons/view-in-browser/index.jsx +++ b/lib/static/components/icons/view-in-browser/index.jsx @@ -6,7 +6,7 @@ import classNames from 'classnames'; import {Eye, EyeSlash} from '@gravity-ui/icons'; import * as actions from '../../../modules/actions'; -import {getRelativeUrl, getUrlWithBase} from '../../../../common-utils'; +import {getUrlWithBase} from '../../../../common-utils'; import './index.styl'; @@ -41,7 +41,7 @@ class ViewInBrowser extends Component { return ( { if (item.label === 'url' || metaInfoBaseUrls[item.label] === 'auto') { - const url = getUrlWithBase(getRelativeUrl(item.content), baseHost); + const url = getUrlWithBase(item.content, baseHost); return { label: item.label, content: getRelativeUrl(item.content), @@ -105,7 +105,7 @@ function MetaInfoInternal(props: MetaInfoInternalProps): ReactNode { metaInfoItemsWithResolvedUrls.push({ label: 'url', content: getRelativeUrl(result.suiteUrl), - url: getUrlWithBase(getRelativeUrl(result.suiteUrl), baseHost) + url: getUrlWithBase(result.suiteUrl, baseHost) }); }