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

Commit

Permalink
Fix: Edit history modal crash (#10834)
Browse files Browse the repository at this point in the history
* failing test

* handle nodes without children in messagediffutils
  • Loading branch information
Kerry authored May 11, 2023
1 parent eac548c commit 41c9687
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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

0 comments on commit 41c9687

Please sign in to comment.