From 70dbe9cfbdbd874cf65077e2c62d379813160a7e Mon Sep 17 00:00:00 2001
From: Will Hunt <will@half-shot.uk>
Date: Fri, 1 Jun 2018 11:22:28 +0100
Subject: [PATCH] Don't try to upload content missing a URL.

---
 src/matrixeventprocessor.ts       |  6 ++++++
 test/test_matrixeventprocessor.ts | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts
index 01f7963..9236e9d 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 d2ca112..56adf89 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();
-- 
GitLab