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

Fix: Edit history modal crash #10834

Merged
merged 4 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/utils/MessageDiffUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ function diffTreeToDOM(desc: Text | HTMLElement): Node {
for (const [key, value] of Object.entries(desc.attributes)) {
node.setAttribute(key, value.value);
}
for (const childDesc of desc.childNodes) {
node.appendChild(diffTreeToDOM(childDesc as Text | HTMLElement));
if (desc.childNodes) {
for (const childDesc of desc.childNodes) {
node.appendChild(diffTreeToDOM(childDesc as Text | HTMLElement));
}
}
return node;
}
Expand Down
1 change: 1 addition & 0 deletions test/utils/MessageDiffUtils-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe("editBodyDiffToHtml", () => {
["attribute modifications", `<a href="#hi">hi</a>`, `<a href="#bye">hi</a>`],
["attribute deletions", `<a href="#hi">hi</a>`, `<a>hi</a>`],
["attribute additions", `<a>hi</a>`, `<a href="#/room/!123">hi</a>`],
["handles empty tags", `<a>hi</a>`, `<a><h1></h1></a> hi`],
])("renders %s", (_label, before, after) => {
const { container } = renderDiff(before, after);
expect(container).toMatchSnapshot();
Expand Down
31 changes: 31 additions & 0 deletions test/utils/__snapshots__/MessageDiffUtils-test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,37 @@ exports[`editBodyDiffToHtml renders element replacements 1`] = `
</div>
`;

exports[`editBodyDiffToHtml renders handles empty tags 1`] = `
<div>
<span
class="mx_EventTile_body markdown-body"
dir="auto"
>
<a
rel="noreferrer noopener"
>
<span>
<span
class="mx_EditHistoryMessage_deletion"
>
hi
</span>
<div
class="mx_EditHistoryMessage_insertion"
>
<h1 />
</div>
</span>
</a>
<span
class="mx_EditHistoryMessage_insertion"
>
hi
</span>
</span>
</div>
`;

exports[`editBodyDiffToHtml renders inline element additions 1`] = `
<div>
<span
Expand Down