Skip to content

Commit

Permalink
Merge pull request #243 from Vandivier/fix-url-parsing
Browse files Browse the repository at this point in the history
fix: parse url
  • Loading branch information
Vandivier authored May 24, 2024
2 parents 4814ce6 + 1752fe5 commit f7b5054
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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: "",
}
}
}

0 comments on commit f7b5054

Please sign in to comment.