m->d: Strip colons from user mentions
This commit is contained in:
		
							parent
							
								
									afbbe0da3d
								
							
						
					
					
						commit
						e73de60d77
					
				
					 2 changed files with 35 additions and 1 deletions
				
			
		| 
						 | 
					@ -401,6 +401,10 @@ async function eventToMessage(event, guild, di) {
 | 
				
			||||||
				return `${attributeValue} data-channel-id="${channelID}">`
 | 
									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.
 | 
								// 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>")
 | 
								input = input.replace(/(?:\n|<br ?\/?>\s*)*<\/blockquote>/g, "</blockquote>")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1556,7 +1556,7 @@ test("event2message: mentioning discord users works", async t => {
 | 
				
			||||||
				msgtype: "m.text",
 | 
									msgtype: "m.text",
 | 
				
			||||||
				body: "wrong body",
 | 
									body: "wrong body",
 | 
				
			||||||
				format: "org.matrix.custom.html",
 | 
									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",
 | 
								event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
 | 
				
			||||||
			origin_server_ts: 1688301929913,
 | 
								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 => {
 | 
					test("event2message: caches the member if the member is not known", async t => {
 | 
				
			||||||
	let called = 0
 | 
						let called = 0
 | 
				
			||||||
	t.deepEqual(
 | 
						t.deepEqual(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue