m->d: Strip colons from user mentions

This commit is contained in:
Cadence Ember 2023-10-28 00:37:20 +13:00
parent afbbe0da3d
commit e73de60d77
2 changed files with 35 additions and 1 deletions

View file

@ -401,6 +401,10 @@ async function eventToMessage(event, guild, di) {
return `${attributeValue} data-channel-id="${channelID}">`
})
// Stripping colons after mentions
input = input.replace(/( data-user-id.*?<\/a>):?/g, "$1")
input = input.replace(/("https:\/\/matrix.to.*?<\/a>):?/g, "$1")
// Element adds a bunch of <br> before </blockquote> but doesn't render them. I can't figure out how this even works in the browser, so let's just delete those.
input = input.replace(/(?:\n|<br ?\/?>\s*)*<\/blockquote>/g, "</blockquote>")

View file

@ -1556,7 +1556,7 @@ test("event2message: mentioning discord users works", async t => {
msgtype: "m.text",
body: "wrong body",
format: "org.matrix.custom.html",
formatted_body: `I'm just <a href="https://matrix.to/#/@_ooye_extremity:cadence.moe"></a> testing mentions`
formatted_body: `I'm just <a href="https://matrix.to/#/@_ooye_extremity:cadence.moe">extremity</a> testing mentions`
},
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
origin_server_ts: 1688301929913,
@ -1639,6 +1639,36 @@ test("event2message: mentioning bridged rooms works", async t => {
)
})
test("event2message: colon after mentions is stripped", async t => {
t.deepEqual(
await eventToMessage({
content: {
msgtype: "m.text",
body: "wrong body",
format: "org.matrix.custom.html",
formatted_body: `<a href="https://matrix.to/#/@_ooye_extremity:cadence.moe">extremity</a>: hey, I'm just <a href="https://matrix.to/#/@rnl:cadence.moe">▲</a>: 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
}
}),
{
messagesToDelete: [],
messagesToEdit: [],
messagesToSend: [{
username: "cadence [they]",
content: "<@114147806469554185> hey, I'm just [▲](<https://matrix.to/#/@rnl:cadence.moe>) testing mentions",
avatar_url: undefined
}]
}
)
})
test("event2message: caches the member if the member is not known", async t => {
let called = 0
t.deepEqual(