Skip to content

Commit

Permalink
fix(pages-components): link's href not obfuscated
Browse files Browse the repository at this point in the history
  • Loading branch information
mkilpatrick committed Jan 7, 2025
1 parent 09bf670 commit b74abaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/pages-components/src/components/link/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ describe("Link", () => {
it("throws an error when cta link is not set", () => {
expect(() => render(<Link cta={{} as CTA} />)).toThrowError();
});

it("renders with obfuscated email when using cta link", () => {
render(<Link cta={{ link: "mailto:test.com" }} />);
const link = screen.getByRole("link");
expect(link.getAttribute("href")).toEqual("bWFpbHRvOnRlc3QuY29t");
});

it("renders with obfuscated email when using href", () => {
render(<Link href="mailto:test.com" />);
const link = screen.getByRole("link");
expect(link.getAttribute("href")).toEqual("bWFpbHRvOnRlc3QuY29t");
});
});

vi.mock("../../components/analytics", () => {
Expand Down Expand Up @@ -71,7 +83,5 @@ describe("Link Component Handles Analytics Failures", () => {

// TODO: Add tests
// Check target="_blank" present on newTab
// Check obfuscated label
// Check obfuscated href
// Check children is label if present
// Check fallback to link for label
2 changes: 1 addition & 1 deletion packages/pages-components/src/components/link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(

// hydration warnings suppressed because they will show when the xYextDebug query param is used
return (
<a {...attributes} {...rest} suppressHydrationWarning={true}>
<a {...rest} {...attributes} suppressHydrationWarning={true}>
{children || link.label || renderedLink}
</a>
);
Expand Down

0 comments on commit b74abaf

Please sign in to comment.