Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix tile crash around tooltipify links #9270

Merged
merged 1 commit into from
Sep 12, 2022
Merged
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
9 changes: 7 additions & 2 deletions src/utils/tooltipify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ export function tooltipifyLinks(rootNodes: ArrayLike<Element>, ignoredNodes: Ele
if (node.tagName === "A" && node.getAttribute("href")
&& node.getAttribute("href") !== node.textContent.trim()
) {
const href = node.getAttribute("href");
let href = node.getAttribute("href");
try {
href = new URL(href, window.location.href).toString();
} catch (e) {
// Not all hrefs will be valid URLs
}

// The node's innerHTML was already sanitized before being rendered in the first place, here we are just
// wrapping the link with the LinkWithTooltip component, keeping the same children. Ideally we'd do this
// without the superfluous span but this is not something React trivially supports at this time.
const tooltip = <LinkWithTooltip tooltip={new URL(href, window.location.href).toString()}>
const tooltip = <LinkWithTooltip tooltip={href}>
<span dangerouslySetInnerHTML={{ __html: node.innerHTML }} />
</LinkWithTooltip>;

Expand Down