Fix translating URL encoded mentions of sim users

This commit is contained in:
Cadence Ember 2024-01-06 19:00:57 +13:00
parent e4f66a5077
commit 83070dcf7e
2 changed files with 34 additions and 1 deletions

View file

@ -448,7 +448,8 @@ async function eventToMessage(event, guild, di) {
}
// Handling mentions of Discord users
input = input.replace(/("https:\/\/matrix.to\/#\/(@[^"]+)")>/g, (whole, attributeValue, mxid) => {
input = input.replace(/("https:\/\/matrix.to\/#\/((?:@|%40)[^"]+)")>/g, (whole, attributeValue, mxid) => {
mxid = decodeURIComponent(mxid)
if (mxUtils.eventSenderIsFromDiscord(mxid)) {
// Handle mention of an OOYE sim user by their mxid
const userID = select("sim", "user_id", {mxid: mxid}).pluck().get()

View file

@ -1663,6 +1663,38 @@ test("event2message: mentioning discord users works", async t => {
)
})
test("event2message: mentioning discord users works when URL encoded", async t => {
t.deepEqual(
await eventToMessage({
content: {
body: "Crunch God a sample message",
format: "org.matrix.custom.html",
formatted_body: `<a href="https://matrix.to/#/%40_ooye_bojack_horseman%3Acadence.moe">Crunch God</a> 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: undefined
}]
}
)
})
test("event2message: mentioning matrix users works", async t => {
t.deepEqual(
await eventToMessage({