Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RouteComponentProps } from 'react-router-dom'
import { getRole } from 'utils/data'
import { useGetAllAplCodeReposQuery, useGetTeamAplCodeReposQuery } from 'redux/otomiApi'
import { useAppSelector } from 'redux/hooks'
import { SAFE_REPO_URL } from 'utils/constants'
import { HeadCell } from '../../../components/EnhancedTable'
import RLink from '../../../components/Link'
import ListTable from '../../../components/ListTable'
Expand All @@ -23,12 +24,20 @@ const getCodeRepoName = (): CallableFunction =>
)
}

const getSafeRepositoryHref = (repositoryUrl: string): string | null => {
if (!SAFE_REPO_URL.test(repositoryUrl)) return null
return `https://${repositoryUrl}`
Comment thread
j-zimnowoda marked this conversation as resolved.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this line is causing an issue. Clicking the link redirects incorrectly due to the duplicated https:// prefix, and it may not work properly with SSH links either.

Image

}

const getCodeRepoUrl = (): CallableFunction =>
function (row): string | React.ReactElement {
const repositoryUrl = row?.spec?.repositoryUrl ?? ''
const repositoryUrl = String(row?.spec?.repositoryUrl ?? '')
const href = getSafeRepositoryHref(repositoryUrl)

if (!href) return repositoryUrl

return (
<a href={repositoryUrl} target='_blank' rel='noopener noreferrer'>
<a href={href} target='_blank' rel='noopener noreferrer'>
{repositoryUrl}
</a>
)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SAFE_REPO_URL =
/^(?:https:\/\/[A-Za-z0-9.-]+\.[A-Za-z]{2,}\/|git@[A-Za-z0-9.-]+\.[A-Za-z]{2,}:|[A-Za-z0-9.-]+\.[A-Za-z]{2,}\/)[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)+(?:\.git)?$/