Skip to content

Don't send filenames in discord message bodies #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/918.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't send filenames in message body when bridging Matrix -> Discord.
2 changes: 1 addition & 1 deletion src/matrixeventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class MatrixEventProcessor {
}

let body: string = "";
if (event.type !== "m.sticker") {
if (!this.HasAttachment(event)) {
const content = event.content!["m.new_content"] ? event.content!["m.new_content"] : event.content;
body = await this.matrixMsgProcessor.FormatMessage(content as IMatrixMessage, channel.guild, params);
}
Expand Down
31 changes: 30 additions & 1 deletion test/test_matrixeventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,35 @@ describe("MatrixEventProcessor", () => {
} as IMatrixEvent, mockChannel as any);
expect(embeds.messageEmbed.description).to.equal("Bunnies\n(<@1234>)");
});
it("Should not send filename in body", async () => {
const {processor} = createMatrixEventProcessor();
const embeds = await processor.EventToEmbed({
content: {
body: "filename.zip",
msgtype: "m.file",
url: "mxc://file",
},
sender: "@test:localhost",
type: "m.room.member",
} as IMatrixEvent, mockChannel as any);
expect(embeds.messageEmbed.description).to.equal("");
});
it("Should not send image filename in body", async () => {
const {processor} = createMatrixEventProcessor();
const embeds = await processor.EventToEmbed({
content: {
body: "filename.jpg",
info: {
mimetype: "image/jpeg",
},
msgtype: "m.image",
url: "mxc://image",
},
sender: "@test:localhost",
type: "m.room.member",
} as IMatrixEvent, mockChannel as any);
expect(embeds.messageEmbed.description).to.equal("");
});
});
describe("HandleAttachment", () => {
const SMALL_FILE = 200;
Expand Down Expand Up @@ -939,7 +968,7 @@ This is the reply`,
type: "m.room.message",
} as IMatrixEvent, mockChannel as any);
expect(result!.image!.url!).to.be.equal("https://fox/localhost");
expect(result!.description).to.be.equal("fox.jpg");
expect(result!.description).to.be.equal("");
});
it("should handle replies to files", async () => {
const {processor} = createMatrixEventProcessor();
Expand Down