Skip to content

Commit

Permalink
is_valid_url
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Dec 30, 2024
1 parent 6879a74 commit 228f8b4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion web/app/components/base/markdown-blocks/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ const MarkdownButton = ({ node }: any) => {
const link = node.properties.dataLink
const size = node.properties.dataSize

function is_valid_url(url: string): boolean {
try {
const parsed_url = new URL(url)
return ['http:', 'https:'].includes(parsed_url.protocol)
}
catch {
return false
}
}

return <Button
variant={variant}
size={size}
className={cn('!h-8 !px-3 select-none')}
onClick={() => {
if (link && (!link.startsWith('http') || !link.startsWith('https'))) {
if (is_valid_url(link)) {
window.open(link, '_blank')
return
}
Expand Down

0 comments on commit 228f8b4

Please sign in to comment.