From 81611b65f8cbdc3e91bec30fdc76cb217d899f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 1 Dec 2024 15:21:25 +0100 Subject: [PATCH] events: Be a little smarter when removing plain reply fallback Given that the default algorithm from the spec would also remove the beginning of a message starting with a blockquote, let's be more conservative an check that the beginning really looks like the fallback that was defined in the spec. --- crates/ruma-events/src/room/message/sanitize.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ruma-events/src/room/message/sanitize.rs b/crates/ruma-events/src/room/message/sanitize.rs index 27b07a23..5a571da8 100644 --- a/crates/ruma-events/src/room/message/sanitize.rs +++ b/crates/ruma-events/src/room/message/sanitize.rs @@ -4,7 +4,10 @@ /// /// [rich reply fallback]: https://spec.matrix.org/latest/client-server-api/#fallbacks-for-rich-replies pub fn remove_plain_reply_fallback(mut s: &str) -> &str { - if !s.starts_with("> ") { + // A reply fallback must begin with a mention of the original sender between `<` and `>`, and + // emotes add `*` as a prefix. If there is no newline, removing the detected fallback would + // result in an empty string. + if (!s.starts_with("> <") && !s.starts_with("> * <")) || !s.contains('\n') { return s; }