Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse url #243

Merged
merged 1 commit into from
May 24, 2024
Merged
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 @@ -5,6 +5,7 @@ import React from "react"
import updateUserChecklistItem from "src/app/user-checklist-items/mutations/updateUserChecklistItem"
import getLatestUserChecklistByName from "src/app/user-checklists/queries/getLatestUserChecklistByName"
import { UserChecklistItemWithChecklistItem } from "src/app/user-checklists/schemas"
import { parseUrl } from "src/core/utils/parsing"

const MAGIC_LINK_SUBSTR = "###LINK###"

Expand Down Expand Up @@ -64,7 +65,7 @@ const UserChecklistItemList = ({
<React.Fragment key={index}>
{part}
<Link
href={{ pathname: checklistItem.linkUri }}
href={parseUrl(checklistItem.linkUri)}
target="_blank"
rel="noreferrer"
className="font-bold hover:underline"
Expand Down
20 changes: 20 additions & 0 deletions src/core/utils/parsing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type ParsedUrl = {
pathname: string
search: string
}

export const parseUrl = (url: string): ParsedUrl => {
try {
const urlObject = new URL(url)

return {
pathname: `${urlObject.origin}${urlObject.pathname}`,
search: urlObject.search,
}
} catch (e) {
return {
pathname: url,
search: "",
}
}
}