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
+11 -2
View File
@@ -6,11 +6,11 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import React, { type ReactElement } from "react";
import { render, screen } from "jest-matrix-react";
import parse from "html-react-parser";
import { bodyToHtml, bodyToNode, formatEmojis, topicToHtml } from "../../src/HtmlUtils";
import { bodyToHtml, bodyToNode, formatEmojis, sanitizedHtmlNode, topicToHtml } from "../../src/HtmlUtils";
import SettingsStore from "../../src/settings/SettingsStore";
import { getMockClientWithEventEmitter } from "../test-utils";
import { SettingLevel } from "../../src/settings/SettingLevel";
@@ -319,3 +319,12 @@ describe("bodyToNode", () => {
jest.resetAllMocks();
});
});
describe("sanitizedHtmlNode", () => {
it("should respect className", () => {
const sanitized = sanitizedHtmlNode('<a href="https://google.com">Link</a>', "testClass");
const { asFragment, getByText } = render(sanitized as ReactElement);
expect(getByText("Link").parentNode).toHaveClass("testClass");
expect(asFragment()).toMatchSnapshot();
});
});