fix(security): incorrect url substring sanitization (#50)

* fix(security): incorrect url substring sanitization

* fix: graceful error handling in git url parsing

* refactor: simplify url parsing logic
This commit is contained in:
Ananth Venkatesh 2024-03-07 09:48:46 -08:00 committed by GitHub
parent 3bdb9ff2e2
commit a2a85696b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,9 +7,19 @@ import Link from 'next/link'
import { Fragment } from 'react'
const getRepo = (link: string) => {
if (link.includes('github.com')) {
const owner = link.split('/')[3]
const name = link.split('/')[4]
let host
try {
host = new URL(link).host
} catch (error) {
console.error('Invalid URL:', link)
return
}
if (host === 'github.com') {
const parts = link.split('/')
const owner = parts[3]
const name = parts[4]
return `git:${owner}/${name}`
}
}