Fix invalid events crashing entire room rather than just their tile (#31256)
* Fix invalid events crashing entire room rather than just their tile Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -939,7 +939,13 @@ for (const evType of ElementCallEventType.names) {
|
|||||||
*/
|
*/
|
||||||
export function hasText(ev: MatrixEvent, client: MatrixClient, showHiddenEvents?: boolean): boolean {
|
export function hasText(ev: MatrixEvent, client: MatrixClient, showHiddenEvents?: boolean): boolean {
|
||||||
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()];
|
||||||
return Boolean(handler?.(ev, client, false, showHiddenEvents));
|
try {
|
||||||
|
return Boolean(handler?.(ev, client, false, showHiddenEvents));
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Error encountered when trying to render event type=${ev.getType()} id=${ev.getId()}`, e);
|
||||||
|
// Returning true if we have a handler so we can show an error tile rather than no tile at all
|
||||||
|
return !!handler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { render } from "jest-matrix-react";
|
|||||||
import { type ReactElement } from "react";
|
import { type ReactElement } from "react";
|
||||||
import { type Mocked, mocked } from "jest-mock";
|
import { type Mocked, mocked } from "jest-mock";
|
||||||
|
|
||||||
import { textForEvent } from "../../src/TextForEvent";
|
import { hasText, textForEvent } from "../../src/TextForEvent";
|
||||||
import SettingsStore from "../../src/settings/SettingsStore";
|
import SettingsStore from "../../src/settings/SettingsStore";
|
||||||
import { createTestClient, stubClient } from "../test-utils";
|
import { createTestClient, stubClient } from "../test-utils";
|
||||||
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
||||||
@@ -700,4 +700,20 @@ describe("TextForEvent", () => {
|
|||||||
).toEqual(result);
|
).toEqual(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("hasText", () => {
|
||||||
|
it("should return true for a known handler given an invalid event", async () => {
|
||||||
|
const cli = stubClient();
|
||||||
|
const ev = new MatrixEvent({
|
||||||
|
type: "m.room.name",
|
||||||
|
content: {
|
||||||
|
name: { foo: "bar" },
|
||||||
|
},
|
||||||
|
state_key: "",
|
||||||
|
room_id: "!roomId",
|
||||||
|
sender: cli.getUserId()!,
|
||||||
|
});
|
||||||
|
expect(hasText(ev, cli, false)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user