From c06356a7710067f3b7f9ffe6aa4eb7d6afcb014a Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:04:29 +0100 Subject: [PATCH 1/8] convert matrix: uris to matrix.to links during m->d --- src/m2d/converters/event-to-message.js | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index b2418fa..87bea0d 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -557,6 +557,83 @@ function serialiseReplyContent(doc) { return body.textContent } +/** + * Replace all matrix: uris in the input string with matrix.to links + * + * @param {string} input + * @returns {string} + */ +function convertMatrixUris(input) { + // this regex is kinda broad, but i'm not really sure how to reasonably make it stricter + // we run the match through the url parser anyway, so if we get a bad match, it should just fail? hopefully? + return input.replace(/(^|\s|")(matrix:[^\s"]+)/g, (match, before, uri) => { + // technically the url might be html-encoded, but since we're gonna splice the url back together, + // and none of the characters that might get html-encoded are actually important to us, it doesn't really matter + // (most of the case it's the query string, and we just copy it over anyway) + // + // try to parse the uri, if we fail just bail + let parsed; + try { + parsed = new URL(uri) + } catch { + return match + } + // the spec permits the url to contain an authority segment, even though it is currently unused + // in the case where someone does include the authority segment, the pathname will start with a / + // otherwise there will be no leading / + // if there is a leading /, remove it + const path = parsed.pathname.slice(parsed.pathname[0] === "/" ? 1 : 0) + + // the path is expected to contain an even number of segments + // if it doesn't, bail + const segments = path.split("/") + if (segments.length % 2 !== 0) { + return match + } + + // we can actually convert matrix: uris to matrix.to links in quite a straight forward way: + // - take pairs of path segments, the first one is the type, the other is an identifier without the sigil + // - map type to an appropriate sigil + // - concatenate with the identifier + // - and that's your new matrix.to path segment + // after transcribing the entire path, add the query at the end of the url + const resultSegments = [] + + while (segments.length > 0) { + const type = segments.shift() + const id = segments.shift() + let sigil + + switch(type) { + case "r": + case "room": + sigil = "#" + break + case "roomid": + sigil = "!" + break + case "e": + case "event": + sigil = "$" + break + case "u": + case "user": + sigil = "@" + break + default: + // unknown type! bail + return match + } + + resultSegments.push(`${encodeURIComponent(sigil)}${id}`) + } + + // now splice the path back together, add the query, and we're done! + // (and don't forget to add the character before the url that we might've matched) + return `${before}https://matrix.to/#/${resultSegments.join("/")}${parsed.search}` + }) +} + /** * @param {Ty.Event.Outer_M_Room_Message | Ty.Event.Outer_M_Room_Message_File | Ty.Event.Outer_M_Sticker | Ty.Event.Outer_M_Room_Message_Encrypted_File | Ty.Event.Outer_Org_Matrix_Msc3381_Poll_Start | Ty.Event.Outer_Org_Matrix_Msc3381_Poll_End} event * @param {DiscordTypes.APIGuild} guild @@ -913,6 +990,9 @@ async function eventToMessage(event, guild, channel, di) { input = `* ${displayName} ${input}` } + // convert matrix: schema uris to "legacy" matrix.to links (thanks, sable) + input = convertMatrixUris(input) + // Handling mentions of Discord users input = input.replace(/("https:\/\/matrix.to\/#\/((?:@|%40)[^"]+)")/g, (whole, attributeValue, mxid) => { mxid = decodeURIComponent(mxid) @@ -1114,6 +1194,7 @@ async function eventToMessage(event, guild, channel, di) { content = `* ${displayName} ${content}` } + content = convertMatrixUris(content) // convert matrix: schema uris to "legacy" matrix.to links (thanks, sable) content = await handleRoomOrMessageLinks(content, di) // Replace matrix.to links with discord.com equivalents where possible let offset = 0 -- 2.34.1 From 18e2421ac5132ac848792b3faee108abc2b7166b Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:34:17 +0100 Subject: [PATCH 2/8] make matrix: uri scheme match case-insensitive --- src/m2d/converters/event-to-message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 87bea0d..1f24906 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -566,7 +566,7 @@ function serialiseReplyContent(doc) { function convertMatrixUris(input) { // this regex is kinda broad, but i'm not really sure how to reasonably make it stricter // we run the match through the url parser anyway, so if we get a bad match, it should just fail? hopefully? - return input.replace(/(^|\s|")(matrix:[^\s"]+)/g, (match, before, uri) => { + return input.replace(/(^|\s|")(matrix:[^\s"]+)/gi, (match, before, uri) => { // technically the url might be html-encoded, but since we're gonna splice the url back together, // and none of the characters that might get html-encoded are actually important to us, it doesn't really matter // (most of the case it's the query string, and we just copy it over anyway) -- 2.34.1 From 919f3e2851d192f23d251c5e5771e2bfc764fac6 Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:40:08 +0100 Subject: [PATCH 3/8] replace switch with if/else, don't encode sigils --- src/m2d/converters/event-to-message.js | 32 ++++++++++---------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 1f24906..412e2c7 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -604,28 +604,20 @@ function convertMatrixUris(input) { const id = segments.shift() let sigil - switch(type) { - case "r": - case "room": - sigil = "#" - break - case "roomid": - sigil = "!" - break - case "e": - case "event": - sigil = "$" - break - case "u": - case "user": - sigil = "@" - break - default: - // unknown type! bail - return match + if (type === "r" || type === "room") { + sigil = "#" + } else if (type === "roomid") { + sigil = "!" + } else if (type === "e" || type === "event") { + sigil = "$" + } else if (type === "u" || type === "user") { + sigil = "@" + } else { + // unknown type! bail + return match } - resultSegments.push(`${encodeURIComponent(sigil)}${id}`) + resultSegments.push(`${sigil}${id}`) } // now splice the path back together, add the query, and we're done! -- 2.34.1 From d7630b60f42ce81b13beebff68e5bf07acad1e33 Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:04:04 +0100 Subject: [PATCH 4/8] use \b + negative lookahead instead of an allowlist of preceding chars for the matrix: uri replacing this allows it to find matrix: uris wrapped in various types of parens, without having to manually specify all of the allowed preceding characters negative lookahead bans non-word characters that could be a part of an uri --- src/m2d/converters/event-to-message.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 412e2c7..74b6d94 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -566,7 +566,7 @@ function serialiseReplyContent(doc) { function convertMatrixUris(input) { // this regex is kinda broad, but i'm not really sure how to reasonably make it stricter // we run the match through the url parser anyway, so if we get a bad match, it should just fail? hopefully? - return input.replace(/(^|\s|")(matrix:[^\s"]+)/gi, (match, before, uri) => { + return input.replace(/(? { // technically the url might be html-encoded, but since we're gonna splice the url back together, // and none of the characters that might get html-encoded are actually important to us, it doesn't really matter // (most of the case it's the query string, and we just copy it over anyway) @@ -621,8 +621,7 @@ function convertMatrixUris(input) { } // now splice the path back together, add the query, and we're done! - // (and don't forget to add the character before the url that we might've matched) - return `${before}https://matrix.to/#/${resultSegments.join("/")}${parsed.search}` + return `https://matrix.to/#/${resultSegments.join("/")}${parsed.search}` }) } -- 2.34.1 From a2482ff9d2e03bf05062ccc21bb5949f83ea9890 Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:55:47 +0100 Subject: [PATCH 5/8] clone some m2d event-to-message tests for matrix: uris --- src/m2d/converters/event-to-message.test.js | 1002 +++++++++++++++++++ 1 file changed, 1002 insertions(+) diff --git a/src/m2d/converters/event-to-message.test.js b/src/m2d/converters/event-to-message.test.js index a77c534..addf8d8 100644 --- a/src/m2d/converters/event-to-message.test.js +++ b/src/m2d/converters/event-to-message.test.js @@ -275,6 +275,46 @@ test("event2message: markdown in link text does not attempt to be escaped becaus ) }) +test("event2message: markdown in link text does not attempt to be escaped because that doesn't work (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + body: "hey mario sports mix [she/her], is it possible to listen on a unix socket?", + format: "org.matrix.custom.html", + formatted_body: "hey mario sports mix [she/her], is it possible to listen on a unix socket?", + "m.mentions": { + "user_ids": [ + "@cadence:cadence.moe" + ] + }, + msgtype: "m.text" + }, + 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: "hey [@mario sports mix [she/her]](), is it possible to listen on a unix socket?", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["roles"], + users: [] + } + }] + } + ) +}) + test("event2message: markdown in link url does not attempt to be escaped (plaintext body, not suppressed)", async t => { t.deepEqual( await eventToMessage({ @@ -3641,6 +3681,40 @@ test("event2message: mentioning discord users works", async t => { ) }) +test("event2message: mentioning discord users works (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `I'm just extremity testing mentions` + }, + 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: "I'm just <@114147806469554185> testing mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning discord users with extra html attributes works", async t => { t.deepEqual( await eventToMessage({ @@ -3684,6 +3758,48 @@ test("event2message: mentioning discord users with extra html attributes works", ) }) +test("event2message: mentioning discord users with extra html attributes works (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@lavender.pet:queer.sh", + content: { + msgtype: "m.text", + body: "also @_ooye_ampflower:cadence.moe fun fact at some point there is plans for FTE to have a built in map editor", + "m.mentions": { + user_ids: [ + "@_ooye_ampflower:cadence.moe" + ] + }, + format: "org.matrix.custom.html", + formatted_body: "

also @Ampflower fun fact at some point there is plans for FTE to have a built in map editor

" + }, + room_id: "!qzDBLKlildpzrrOnFZ:cadence.moe", + origin_server_ts: 1778616745263, + unsigned: { + age: 100363692, + membership: "join" + }, + event_id: "$AHCkieLEVCrCEA3INTCl0rh44V29fCASlZpBKw7DzQU", + user_id: "@lavender.pet:queer.sh", + age: 100363692 + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "lavender.pet", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=L&hue=30", + content: "also <@196188877885538304> fun fact at some point there is plans for FTE to have a built in map editor", + allowed_mentions: { + parse: ["roles"], + users: ["196188877885538304"] + } + }] + } + ) +}) test("event2message: mentioning discord users works when URL encoded", async t => { t.deepEqual( @@ -3719,6 +3835,40 @@ test("event2message: mentioning discord users works when URL encoded", async t = ) }) +test("event2message: mentioning discord users works when URL encoded (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + body: "Crunch God a sample message", + format: "org.matrix.custom.html", + formatted_body: `Crunch God a sample message`, + msgtype: "m.text" + }, + 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: "<@771520384671416320> a sample message", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning PK discord users works", async t => { t.deepEqual( await eventToMessage({ @@ -3753,6 +3903,40 @@ test("event2message: mentioning PK discord users works", async t => { ) }) +test("event2message: mentioning PK discord users works (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `I'm just Azalea testing mentions` + }, + 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: "I'm just **@Azalea &flwr; 🌺** (<@196188877885538304>) testing mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning matrix users works", async t => { t.deepEqual( await eventToMessage({ @@ -3787,6 +3971,40 @@ test("event2message: mentioning matrix users works", async t => { ) }) +test("event2message: mentioning matrix users works (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `I'm just ▲ testing mentions` + }, + 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: "I'm just [@▲]() testing mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: matrix mentions are not double-escaped when embed links permission is denied", async t => { t.deepEqual( await eventToMessage({ @@ -3828,6 +4046,47 @@ test("event2message: matrix mentions are not double-escaped when embed links per ) }) +test("event2message: matrix mentions are not double-escaped when embed links permission is denied (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `I'm just ▲ testing mentions` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, { + id: "123", + roles: [{ + id: "123", + name: "@everyone", + permissions: DiscordTypes.PermissionFlagsBits.SendMessages + }] + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "I'm just [@▲]() testing mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: multiple mentions are both escaped", async t => { t.deepEqual( await eventToMessage({ @@ -3862,6 +4121,40 @@ test("event2message: multiple mentions are both escaped", async t => { ) }) +test("event2message: multiple mentions are both escaped (matrix: uri edition)", 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: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning matrix users works even when Element disambiguates the user", async t => { t.deepEqual( await eventToMessage({ @@ -3892,6 +4185,36 @@ test("event2message: mentioning matrix users works even when Element disambiguat ) }) +test("event2message: mentioning matrix users works even when Element disambiguates the user (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "unascribed @unascribed:sleeping.town: if you want to run some experimental software, `11864f80cf` branch of OOYE has _vastly_ improved handling of PluralKit users. feel free to try it out, if you find bugs I'd appreciate you letting me know (just tag me at the place in chat where something went wrong)", + format: "org.matrix.custom.html", + formatted_body: "unascribed @unascribed:sleeping.town: if you want to run some experimental software, 11864f80cf branch of OOYE has vastly improved handling of PluralKit users. feel free to try it out, if you find bugs I'd appreciate you letting me know (just tag me at the place in chat where something went wrong)" + }, + event_id: "$17qTyvkDykSp_4Wkjeuh9Y6j9hPe20ZY_E6V3UKAyUE", + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "[@unascribed]() if you want to run some experimental software, `11864f80cf` branch of OOYE has _vastly_ improved handling of PluralKit users. feel free to try it out, if you find bugs I'd appreciate you letting me know (just tag me at the place in chat where something went wrong)", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning bridged rooms works", async t => { t.deepEqual( await eventToMessage({ @@ -3926,6 +4249,40 @@ test("event2message: mentioning bridged rooms works", async t => { ) }) +test("event2message: mentioning bridged rooms works (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `I'm just worm-farm testing channel mentions` + }, + 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: "I'm just <#1100319550446252084> testing channel mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning bridged rooms works (plaintext body)", async t => { t.deepEqual( await eventToMessage({ @@ -3958,6 +4315,38 @@ test("event2message: mentioning bridged rooms works (plaintext body)", async t = ) }) +test("event2message: mentioning bridged rooms works (plaintext body, matrix uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: `I'm just matrix:roomid/BnKuBPCvyfOkhcUjEu:cadence.moe?via=cadence.moe testing channel mentions` + }, + 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: "I'm just <#1100319550446252084> testing channel mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning bridged rooms by alias works", async t => { let called = 0 t.deepEqual( @@ -4002,6 +4391,50 @@ test("event2message: mentioning bridged rooms by alias works", async t => { t.equal(called, 1) }) +test("event2message: mentioning bridged rooms by alias works (matrix: uri edition)", async t => { + let called = 0 + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `I'm just worm-farm testing channel mentions` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, {}, {}, { + api: { + async getAlias(alias) { + called++ + t.equal(alias, "#worm-farm:cadence.moe") + return "!BnKuBPCvyfOkhcUjEu:cadence.moe" + } + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "I'm just <#1100319550446252084> testing channel mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) + t.equal(called, 1) +}) + test("event2message: mentioning bridged rooms by alias works (plaintext body)", async t => { let called = 0 t.deepEqual( @@ -4044,6 +4477,48 @@ test("event2message: mentioning bridged rooms by alias works (plaintext body)", t.equal(called, 1) }) +test("event2message: mentioning bridged rooms by alias works (plaintext body, matrix: uri edition)", async t => { + let called = 0 + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: `I'm just matrix:r/worm-farm:cadence.moe?via=cadence.moe testing channel mentions` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, {}, {}, { + api: { + async getAlias(alias) { + called++ + t.equal(alias, "#worm-farm:cadence.moe") + return "!BnKuBPCvyfOkhcUjEu:cadence.moe" + } + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "I'm just <#1100319550446252084> testing channel mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) + t.equal(called, 1) +}) + test("event2message: mentioning bridged rooms by alias skips the link when alias is unresolvable", async t => { let called = 0 t.deepEqual( @@ -4085,6 +4560,47 @@ test("event2message: mentioning bridged rooms by alias skips the link when alias t.equal(called, 1) }) +test("event2message: mentioning bridged rooms by alias skips the link when alias is unresolvable (matrix: uri edition)", async t => { + let called = 0 + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: `I'm just matrix:r/worm-farm:cadence.moe?via=cadence.moe and matrix:roomid/BnKuBPCvyfOkhcUjEu:cadence.moe?via=cadence.moe testing channel mentions` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, {}, {}, { + api: { + async getAlias(alias) { + called++ + throw new MatrixServerError("Alias doesn't exist or something") + } + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "I'm just and <#1100319550446252084> testing channel mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) + t.equal(called, 1) +}) + test("event2message: mentioning known bridged events works (plaintext body)", async t => { t.deepEqual( await eventToMessage({ @@ -4117,6 +4633,38 @@ test("event2message: mentioning known bridged events works (plaintext body)", as ) }) +test("event2message: mentioning known bridged events works (plaintext body, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "it was uploaded earlier in matrix:roomid/CzvdIdUQXgUjDVKxeU:cadence.moe/e/zXSlyI78DQqQwwfPUSzZ1b-nXzbUrCDljJgnGDdoI10?via=cadence.moe, take a look!" + }, + 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: "it was uploaded earlier in https://discord.com/channels/497159726455455754/497161350934560778/1141619794500649020, take a look!", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning known bridged events works (partially formatted body)", async t => { t.deepEqual( await eventToMessage({ @@ -4151,6 +4699,40 @@ test("event2message: mentioning known bridged events works (partially formatted ) }) +test("event2message: mentioning known bridged events works (partially formatted body, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `it was uploaded earlier in matrix:roomid/CzvdIdUQXgUjDVKxeU:cadence.moe/e/zXSlyI78DQqQwwfPUSzZ1b-nXzbUrCDljJgnGDdoI10?via=cadence.moe` + }, + 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: "it was uploaded earlier in https://discord.com/channels/497159726455455754/497161350934560778/1141619794500649020", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning known bridged events works (formatted body)", async t => { t.deepEqual( await eventToMessage({ @@ -4185,6 +4767,40 @@ test("event2message: mentioning known bridged events works (formatted body)", as ) }) +test("event2message: mentioning known bridged events works (formatted body, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `it was uploaded earlier in amanda-spam` + }, + 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: "it was uploaded earlier in https://discord.com/channels/497159726455455754/497161350934560778/1141619794500649020", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning known bridged events followed by line break and user mention works (partially formatted body)", async t => { t.deepEqual( await eventToMessage({ @@ -4219,6 +4835,40 @@ test("event2message: mentioning known bridged events followed by line break and ) }) +test("event2message: mentioning known bridged events followed by line break and user mention works (partially formatted body, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `matrix:roomid/CzvdIdUQXgUjDVKxeU:cadence.moe/e/zXSlyI78DQqQwwfPUSzZ1b-nXzbUrCDljJgnGDdoI10?via=cadence.moeextremity` + }, + 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: "https://discord.com/channels/497159726455455754/497161350934560778/1141619794500649020<@114147806469554185>", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: mentioning unknown bridged events can approximate with timestamps", async t => { let called = 0 t.deepEqual( @@ -4266,6 +4916,53 @@ test("event2message: mentioning unknown bridged events can approximate with time t.equal(called, 1, "getEvent should be called once") }) +test("event2message: mentioning unknown bridged events can approximate with timestamps (matrix: uri edition)", async t => { + let called = 0 + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `it was uploaded years ago in amanda-spam` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, {}, {}, { + api: { + async getEvent(roomID, eventID) { + called++ + t.equal(roomID, "!CzvdIdUQXgUjDVKxeU:cadence.moe") + t.equal(eventID, "$zpzx6ABetMl8BrpsFbdZ7AefVU1Y_-t97bJRJM2JyW0") + return { + origin_server_ts: 1599813121000 + } + } + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "it was uploaded years ago in https://discord.com/channels/497159726455455754/497161350934560778/753895613661184000", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) + t.equal(called, 1, "getEvent should be called once") +}) + test("event2message: mentioning events falls back to original link when server doesn't know about it", async t => { let called = 0 t.deepEqual( @@ -4311,6 +5008,51 @@ test("event2message: mentioning events falls back to original link when server d t.equal(called, 1, "getEvent should be called once") }) +test("event2message: mentioning events falls back to original link when server doesn't know about it (matrix: uri edition)", async t => { + let called = 0 + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `it was uploaded years ago in amanda-spam` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOV", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, {}, {}, { + api: { + async getEvent(roomID, eventID) { + called++ + t.equal(roomID, "!CzvdIdUQXgUjDVKxeU:cadence.moe") + t.equal(eventID, "$zpzx6ABetMl8BrpsFbdZ7AefVU1Y_-t97bJRJM2JyW1") + throw new Error("missing event or something") + } + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "it was uploaded years ago in [amanda-spam]()", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) + t.equal(called, 1, "getEvent should be called once") +}) + test("event2message: mentioning events falls back to original link when the channel-guild isn't in cache", async t => { t.equal(select("channel_room", "channel_id", {room_id: "!tnedrGVYKFNUdnegvf:tchncs.de"}).pluck().get(), "489237891895768942", "consistency check: this channel-room needs to be in the database for the test to make sense") t.equal(discord.channels.get("489237891895768942"), undefined, "consistency check: this channel needs to not be in client cache for the test to make sense") @@ -4354,6 +5096,49 @@ test("event2message: mentioning events falls back to original link when the chan ) }) +test("event2message: mentioning events falls back to original link when the channel-guild isn't in cache (matrix: uri edition)", async t => { + t.equal(select("channel_room", "channel_id", {room_id: "!tnedrGVYKFNUdnegvf:tchncs.de"}).pluck().get(), "489237891895768942", "consistency check: this channel-room needs to be in the database for the test to make sense") + t.equal(discord.channels.get("489237891895768942"), undefined, "consistency check: this channel needs to not be in client cache for the test to make sense") + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `it was uploaded years ago in ex-room-doesnt-exist-any-more` + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOX", + origin_server_ts: 1688301929913, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: { + age: 405299 + } + }, {}, {}, { + api: { + /* c8 ignore next 3 */ + async getEvent() { + t.fail("getEvent should not be called because it should quit early due to no channel-guild") + } + } + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "it was uploaded years ago in [ex-room-doesnt-exist-any-more]()", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: link to event in an unknown room (href link)", async t => { t.deepEqual( await eventToMessage({ @@ -4384,6 +5169,36 @@ test("event2message: link to event in an unknown room (href link)", async t => { ) }) +test("event2message: link to event in an unknown room (href link, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: 'ah yeah, here\'s where the bug was reported: matrix:roomid/QtykxKocfZaZOUrTwp:matrix.org/e/1542477546853947KGhZL:matrix.org' + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "ah yeah, here's where the bug was reported: ", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: link to event in an unknown room (bare link)", async t => { t.deepEqual( await eventToMessage({ @@ -4414,6 +5229,36 @@ test("event2message: link to event in an unknown room (bare link)", async t => { ) }) +test("event2message: link to event in an unknown room (bare link, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: "PK API failure, tho idk how you'd handle that matrix:roomid/SeYQChwXBnZaQLoZfI:sleeping.town/e/AAPZ56B2P7TfROYPTtuoJjgvXmaBM11NoNceM8GCJ7s", + msgtype: "m.text" + }, + sender: "@cadence:cadence.moe", + type: "m.room.message", + event_id: "$-UwntiHseGfch1GMjTROIgDbgLGIOwMx0vJdTi-dmok", + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe" + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "PK API failure, tho idk how you'd handle that ", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: link to event in an unknown room (plaintext)", async t => { t.deepEqual( await eventToMessage({ @@ -4442,6 +5287,34 @@ test("event2message: link to event in an unknown room (plaintext)", async t => { ) }) +test("event2message: link to event in an unknown room (plaintext, matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "ah yeah, here's where the bug was reported: matrix:roomid/QtykxKocfZaZOUrTwp:matrix.org/e/1542477546853947KGhZL:matrix.org" + }, + event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU", + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + }), + { + ensureJoined: [], + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "ah yeah, here's where the bug was reported: ", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: colon after mentions is stripped", async t => { t.deepEqual( await eventToMessage({ @@ -4476,6 +5349,40 @@ test("event2message: colon after mentions is stripped", async t => { ) }) +test("event2message: colon after mentions is stripped (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + content: { + msgtype: "m.text", + body: "wrong body", + format: "org.matrix.custom.html", + formatted_body: `extremity: hey, I'm just ▲: testing mentions` + }, + 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: "<@114147806469554185> hey, I'm just [@▲]() testing mentions", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }] + } + ) +}) + test("event2message: caches the member if the member is not known", async t => { let called = 0 t.deepEqual( @@ -5554,6 +6461,36 @@ test("event2message: guessed @mentions work with other matrix bridge old users", ) }) +test("event2message: guessed @mentions work with other matrix bridge old users (matrix: uri edition)", async t => { + t.deepEqual( + await eventToMessage({ + type: "m.room.message", + sender: "@cadence:cadence.moe", + content: { + msgtype: "m.text", + body: "extremity#0: zenosia#0717: back me up on this sentiment, if not necessarily the phrasing", + format: "org.matrix.custom.html", + formatted_body: "extremity#0: zenosia#0717: back me up on this sentiment, if not necessarily the phrasing" + }, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + event_id: "$SiXetU9h9Dg-M9Frcw_C6ahnoXZ3QPZe3MVJR5tcB9A" + }), + { + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "<@114147806469554185> <@176943908762006200> back me up on this sentiment, if not necessarily the phrasing", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + parse: ["users", "roles"] + } + }], + ensureJoined: [] // we already think it worked on Matrix side due to the pill, so no need for the OOYE sim user to join the room to indicate success. + } + ) +}) + test("event2message: @room converts to @everyone and is allowed when the room doesn't restrict who can use it (plaintext body)", async t => { let called = 0 t.deepEqual( @@ -5680,6 +6617,71 @@ test("event2message: @room converts to @everyone (formatted body with weird room ) }) +test("event2message: @room converts to @everyone (formatted body with weird room link, matrix: uri edition)", async t => { + let called = 0 + t.deepEqual( + await eventToMessage({ + content: { + body: "> can you\n@room", + format: "org.matrix.custom.html", + formatted_body: "
can you


@room", + "m.mentions": { + room: true + }, + msgtype: "m.text" + }, + event_id: "$lp26s6ARdYKSgipe1N4rBJymaO74zlkJxHb-dJws-vA", + origin_server_ts: 1791883507643, + room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe", + sender: "@cadence:cadence.moe", + type: "m.room.message", + unsigned: {} + }, data.guild.general, data.channel.general, { + api: { + async getStateEvent(roomID, type, key) { + called++ + t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe") + t.equal(type, "m.room.power_levels") + t.equal(key, "") + return { + users: {}, + notifications: { + room: 0 + } + } + }, + async getStateEventOuter(roomID, type, key) { + t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe") + t.equal(type, "m.room.create") + t.equal(key, "") + return { + type: "m.room.create", + state_key: "", + sender: "@_ooye_bot:cadence.moe", + content: { + room_version: "11" + } + } + } + } + }), + { + messagesToDelete: [], + messagesToEdit: [], + messagesToSend: [{ + username: "cadence [they]", + content: "> can you\n@everyone", + avatar_url: "https://bridge.example.org/download/letter-avatar?letter=C&hue=90", + allowed_mentions: { + users: [], + parse: ["roles", "everyone"] + } + }], + ensureJoined: [] + } + ) +}) + test("event2message: @room is converted to a role in configured rooms", async t => { let called = 0 t.deepEqual( -- 2.34.1 From 632647329620eb6c299700389bfd97e92b7a198d Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:56:26 +0100 Subject: [PATCH 6/8] make the matrix: uri regex stricter some of the "new" tests found an edge case in the previous, lenient regex pattern making it stricter fixes the failures --- src/m2d/converters/event-to-message.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 74b6d94..48f014b 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -564,9 +564,7 @@ function serialiseReplyContent(doc) { * @returns {string} */ function convertMatrixUris(input) { - // this regex is kinda broad, but i'm not really sure how to reasonably make it stricter - // we run the match through the url parser anyway, so if we get a bad match, it should just fail? hopefully? - return input.replace(/(? { + return input.replace(/(? { // technically the url might be html-encoded, but since we're gonna splice the url back together, // and none of the characters that might get html-encoded are actually important to us, it doesn't really matter // (most of the case it's the query string, and we just copy it over anyway) -- 2.34.1 From b40382da080a121df15cc266116eb18ca488fd16 Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 03:01:09 +0100 Subject: [PATCH 7/8] allow & in the matrix: uri regex --- src/m2d/converters/event-to-message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 48f014b..5c9ba41 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -564,7 +564,7 @@ function serialiseReplyContent(doc) { * @returns {string} */ function convertMatrixUris(input) { - return input.replace(/(? { + return input.replace(/(? { // technically the url might be html-encoded, but since we're gonna splice the url back together, // and none of the characters that might get html-encoded are actually important to us, it doesn't really matter // (most of the case it's the query string, and we just copy it over anyway) -- 2.34.1 From 3e080e8187d4fee6b295eeef1c87260e199c5c56 Mon Sep 17 00:00:00 2001 From: mini-bomba <55105495+mini-bomba@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:51:12 +0100 Subject: [PATCH 8/8] add % to the matrix: uri regex in case someone (sable) decides to percent-encode the id for some reason --- src/m2d/converters/event-to-message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 5c9ba41..0191ef1 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -564,7 +564,7 @@ function serialiseReplyContent(doc) { * @returns {string} */ function convertMatrixUris(input) { - return input.replace(/(? { + return input.replace(/(? { // technically the url might be html-encoded, but since we're gonna splice the url back together, // and none of the characters that might get html-encoded are actually important to us, it doesn't really matter // (most of the case it's the query string, and we just copy it over anyway) -- 2.34.1