From e66822e94b3b766a63a1fe88de9295c8a40835ad Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 9 Feb 2026 13:22:36 +1300 Subject: [PATCH] Make sure written mentions do not match in URLs --- src/d2m/converters/message-to-event.js | 3 ++- src/d2m/converters/message-to-event.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/d2m/converters/message-to-event.js b/src/d2m/converters/message-to-event.js index 2f12958..460b743 100644 --- a/src/d2m/converters/message-to-event.js +++ b/src/d2m/converters/message-to-event.js @@ -721,7 +721,8 @@ async function messageToEvent(message, guild, options = {}, di) { const m = matches[i] const prefix = m[1] const maximumWrittenSection = m[2].toLowerCase() - if (maximumWrittenSection.match(/^!?&?[0-9]+>/) || maximumWrittenSection.match(/^everyone\b/) || maximumWrittenSection.match(/^here\b/)) continue + if (m.index > 0 && !content[m.index-1].match(/ |\(|\n/)) continue // must have space before it + if (maximumWrittenSection.match(/^everyone\b/) || maximumWrittenSection.match(/^here\b/)) continue // ignore @everyone/@here var roomID = roomID ?? select("channel_room", "room_id", {channel_id: message.channel_id}).pluck().get() assert(roomID) diff --git a/src/d2m/converters/message-to-event.test.js b/src/d2m/converters/message-to-event.test.js index 7a7d86f..84cc1e0 100644 --- a/src/d2m/converters/message-to-event.test.js +++ b/src/d2m/converters/message-to-event.test.js @@ -947,6 +947,21 @@ test("message2event: written @mentions may match part of the mxid", async t => { }]) }) +test("message2event: written @mentions do not match in URLs", async t => { + const events = await messageToEvent({ + ...data.message.advanced_written_at_mention_for_matrix, + content: "the fucking around with pixel composer continues https://pub.mastodon.sleeping.town/@exa/116037641900024965" + }, data.guild.general, {}, {}) + t.deepEqual(events, [{ + $type: "m.room.message", + "m.mentions": {}, + msgtype: "m.text", + body: "the fucking around with pixel composer continues https://pub.mastodon.sleeping.town/@exa/116037641900024965", + format: "org.matrix.custom.html", + formatted_body: `the fucking around with pixel composer continues https://pub.mastodon.sleeping.town/@exa/116037641900024965` + }]) +}) + test("message2event: entire message may match elaborate display name", async t => { let called = 0 const events = await messageToEvent({