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:
parent
3bdb9ff2e2
commit
a2a85696b5
1 changed files with 13 additions and 3 deletions
|
@ -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}`
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue