diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 01f796392b6802c87b5169897141c286f196aa8d..9236e9d0ee4cb837bad3111ef9c786dcf8a795f0 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -126,11 +126,17 @@ export class MatrixEventProcessor { if (!hasAttachment) { return ""; } + if (event.content.info == null) { log.info("Event was an attachment type but was missing a content.info"); return ""; } + if (event.content.url == null) { + log.info("Event was an attachment type but was missing a content.url"); + return ""; + } + let size = event.content.info.size || 0; const url = mxClient.mxcUrlToHttp(event.content.url); const name = this.GetFilenameForMediaEvent(event.content); diff --git a/test/test_matrixeventprocessor.ts b/test/test_matrixeventprocessor.ts index d2ca112d634a8cc975ca3da74dbfc54bffd8e058..56adf8910ba316399804687bf218bdc34145700b 100644 --- a/test/test_matrixeventprocessor.ts +++ b/test/test_matrixeventprocessor.ts @@ -350,6 +350,17 @@ describe("MatrixEventProcessor", () => { }, }, mxClient)).to.eventually.eq(""); }); + it("message without a url", () => { + const processor = createMatrixEventProcessor(); + return expect(processor.HandleAttachment({ + content: { + msgtype: "m.video", + info: { + size: 1, + }, + }, + }, mxClient)).to.eventually.eq(""); + }); it("message with a large info.size", () => { const LARGE_FILE = 8000000; const processor = createMatrixEventProcessor();