From 8fb188f4a836ff9bf172ff0a55412cf4376a0790 Mon Sep 17 00:00:00 2001
From: Sorunome <mail@sorunome.de>
Date: Sun, 12 May 2019 13:14:10 +0200
Subject: [PATCH] also filter out embeds with trailing slash in URL properly

---
 src/discordmessageprocessor.ts       |  6 +++++-
 test/test_discordmessageprocessor.ts | 31 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/discordmessageprocessor.ts b/src/discordmessageprocessor.ts
index 475a526..d1328fe 100644
--- a/src/discordmessageprocessor.ts
+++ b/src/discordmessageprocessor.ts
@@ -295,7 +295,11 @@ export class DiscordMessageProcessor {
         if (!embed.url) {
             return false;
         }
-        return msg.content.includes(embed.url);
+        let url = embed.url;
+        if (url.substr(url.length - 1) === "/") {
+            url = url.substr(0, url.length - 1);
+        }
+        return msg.content.includes(url);
     }
 
     private getDiscordParseCallbacks(msg: Discord.Message) {
diff --git a/test/test_discordmessageprocessor.ts b/test/test_discordmessageprocessor.ts
index 68206a5..b77aa75 100644
--- a/test/test_discordmessageprocessor.ts
+++ b/test/test_discordmessageprocessor.ts
@@ -184,6 +184,37 @@ describe("DiscordMessageProcessor", () => {
             Chai.assert.equal(result.formattedBody, "message <a href=\"http://example.com\">" +
                 "http://example.com</a>");
         });
+        it("should ignore same-url embeds with trailing slash", async () => {
+            const processor = new DiscordMessageProcessor(
+                new DiscordMessageProcessorOpts("localhost"), bot as DiscordBot);
+            const msg = new MockMessage() as any;
+            msg.embeds = [
+                {
+                    author: {} as any,
+                    client: {} as any,
+                    color: {} as any,
+                    createdAt: {} as any,
+                    createdTimestamp: {} as any,
+                    description: "Description",
+                    fields: [] as any,
+                    footer: {} as any,
+                    hexColor: {} as any,
+                    image: {} as any,
+                    message: {} as any,
+                    provider: {} as any,
+                    thumbnail: {} as any,
+                    title: "Title",
+                    type: {} as any,
+                    url: "http://example.com/",
+                    video: {} as any,
+                },
+            ];
+            msg.content = "message http://example.com";
+            const result = await processor.FormatMessage(msg);
+            Chai.assert.equal(result.body, "message http://example.com");
+            Chai.assert.equal(result.formattedBody, "message <a href=\"http://example.com\">" +
+                "http://example.com</a>");
+        });
     });
     describe("FormatEdit", () => {
         it("should format basic edits appropriately", async () => {
-- 
GitLab