Apply html utils sanitiser to embedded page (#33842)

* Apply html utils sanitiser to embedded page

* Write tests
This commit is contained in:
Michael Telatynski
2026-06-15 12:58:56 +00:00
committed by GitHub
parent 0f0f8c6ba2
commit 7949980a7e
6 changed files with 82 additions and 6 deletions
@@ -47,4 +47,13 @@ describe("<EmbeddedPage />", () => {
const { asFragment } = render(<EmbeddedPage />);
expect(asFragment()).toMatchSnapshot();
});
it("should sanitise input", async () => {
fetchMock.get("https://other.page", `<h1>Foo</h1><iframe src="https://home.page" />`);
const { asFragment } = render(<EmbeddedPage url="https://other.page" />);
await expect(screen.findByText("Foo")).resolves.toBeVisible();
expect(screen.queryByRole("iframe")).not.toBeInTheDocument();
expect(asFragment()).toMatchSnapshot();
});
});
@@ -7,11 +7,29 @@ exports[`<EmbeddedPage /> should render nothing if no url given 1`] = `
>
<div
class="undefined_body"
dir="auto"
/>
</div>
</DocumentFragment>
`;
exports[`<EmbeddedPage /> should sanitise input 1`] = `
<DocumentFragment>
<div
class="undefined_guest"
>
<div
class="undefined_body"
dir="auto"
>
<h1>
Foo
</h1>
</div>
</div>
</DocumentFragment>
`;
exports[`<EmbeddedPage /> should show error if unable to load 1`] = `
<DocumentFragment>
<div
@@ -19,6 +37,7 @@ exports[`<EmbeddedPage /> should show error if unable to load 1`] = `
>
<div
class="undefined_body"
dir="auto"
>
Couldn't load page
</div>
@@ -33,6 +52,7 @@ exports[`<EmbeddedPage /> should translate _t strings ["] 1`] = `
>
<div
class="undefined_body"
dir="auto"
>
<h1>
Przeglądaj pokoje
@@ -49,6 +69,7 @@ exports[`<EmbeddedPage /> should translate _t strings [&#27;] 1`] = `
>
<div
class="undefined_body"
dir="auto"
>
<h1>
Przeglądaj pokoje
@@ -65,6 +86,7 @@ exports[`<EmbeddedPage /> should translate _t strings [&#34;] 1`] = `
>
<div
class="undefined_body"
dir="auto"
>
<h1>
Przeglądaj pokoje
@@ -81,6 +103,7 @@ exports[`<EmbeddedPage /> should translate _t strings ['] 1`] = `
>
<div
class="undefined_body"
dir="auto"
>
<h1>
Przeglądaj pokoje