diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js
index 87fadc8..f9403f9 100644
--- a/m2d/converters/event-to-message.js
+++ b/m2d/converters/event-to-message.js
@@ -724,7 +724,7 @@ async function eventToMessage(event, guild, di) {
content = turndownService.turndown(root)
// Put < > around any surviving matrix.to links to hide the URL previews
- content = content.replace(/\bhttps?:\/\/matrix\.to\/[^ )]*/, "<$&>")
+ content = content.replace(/\bhttps?:\/\/matrix\.to\/[^ )]*/g, "<$&>")
// It's designed for commonmark, we need to replace the space-space-newline with just newline
content = content.replace(/ \n/g, "\n")
diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js
index 90da51c..9035ddb 100644
--- a/m2d/converters/event-to-message.test.js
+++ b/m2d/converters/event-to-message.test.js
@@ -2619,6 +2619,40 @@ test("event2message: mentioning matrix users works", async t => {
)
})
+test("event2message: multiple mentions are both escaped", async t => {
+ t.deepEqual(
+ await eventToMessage({
+ content: {
+ msgtype: "m.text",
+ body: "wrong body",
+ format: "org.matrix.custom.html",
+ formatted_body: `@cadence:cadence.moe can you kick my old account over there @amyiscoolz:matrix.atiusamy.com`
+ },
+ event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
+ origin_server_ts: 1688301929913,
+ room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe",
+ sender: "@cadence:cadence.moe",
+ type: "m.room.message",
+ unsigned: {
+ age: 405299
+ }
+ }),
+ {
+ ensureJoined: [],
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "[@cadence:cadence.moe]() can you kick my old account over there [@amyiscoolz:matrix.atiusamy.com]()",
+ avatar_url: undefined,
+ allowed_mentions: {
+ parse: ["users", "roles"]
+ }
+ }]
+ }
+ )
+})
+
test("event2message: mentioning matrix users works even when Element disambiguates the user", async t => {
t.deepEqual(
await eventToMessage({