Make sure written mentions do not match in URLs

This commit is contained in:
Cadence Ember
2026-02-09 13:22:36 +13:00
parent b463e1173b
commit e66822e94b
2 changed files with 17 additions and 1 deletions

View File

@@ -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)

View File

@@ -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 <a href="https://pub.mastodon.sleeping.town/@exa/116037641900024965">https://pub.mastodon.sleeping.town/@exa/116037641900024965</a>`
}])
})
test("message2event: entire message may match elaborate display name", async t => {
let called = 0
const events = await messageToEvent({