diff --git a/src/discordmessageprocessor.ts b/src/discordmessageprocessor.ts index 475a5267bf6b9791a7adaa23aebeebe3700ce2af..d1328fe7c5aa6e11ee5fefa35d444bf444b63fc3 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 68206a5ed9ab3b68a4ef784b1e5caef4eed32276..38649ddc80d55dcd301812710a477759d868e993 100644 --- a/test/test_discordmessageprocessor.ts +++ b/test/test_discordmessageprocessor.ts @@ -1,5 +1,5 @@ /* -Copyright 2017, 2018 matrix-appservice-discord +Copyright 2017 - 2019 matrix-appservice-discord Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -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 () => {