From 806d389e132710079e9c50b772a25de22926e038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 1 Jun 2022 10:27:20 +0200 Subject: [PATCH] events: Don't send pretty-printed HTML fallback in replies --- crates/ruma-common/Cargo.toml | 3 +- .../src/events/room/message/reply.rs | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/crates/ruma-common/Cargo.toml b/crates/ruma-common/Cargo.toml index 8da69d67..a22c27b0 100644 --- a/crates/ruma-common/Cargo.toml +++ b/crates/ruma-common/Cargo.toml @@ -23,7 +23,7 @@ server = [] api = ["http", "thiserror"] compat = ["ruma-macros/compat", "ruma-identifiers-validation/compat"] -events = ["indoc", "thiserror"] +events = ["thiserror"] # TODO: Use weak dependency features once MSRV >= 1.60 js = ["js-sys", "getrandom/js", "uuid/js"] markdown = ["pulldown-cmark"] @@ -56,7 +56,6 @@ form_urlencoded = "1.0.0" getrandom = { version = "0.2.6", optional = true } http = { version = "0.2.2", optional = true } indexmap = { version = "1.6.2", features = ["serde-1"] } -indoc = { version = "1.0", optional = true } itoa = "1.0.1" js_int = { version = "0.2.0", features = ["serde"] } js_option = "0.1.0" diff --git a/crates/ruma-common/src/events/room/message/reply.rs b/crates/ruma-common/src/events/room/message/reply.rs index 963d9fac..732a5673 100644 --- a/crates/ruma-common/src/events/room/message/reply.rs +++ b/crates/ruma-common/src/events/room/message/reply.rs @@ -1,7 +1,5 @@ use std::fmt; -use indoc::formatdoc; - use super::{FormattedBody, MessageType, OriginalRoomMessageEvent}; pub fn get_message_quote_fallbacks( @@ -44,17 +42,15 @@ fn get_quotes( ( format!("> {emote_sign}<{sender}> {body}").replace('\n', "\n> "), - formatdoc!( - " - -
- In reply to - {emote_sign}{sender} -
- {html_body} -
-
- " + format!( + "\ +
\ + In reply to \ + {emote_sign}{sender}\ +
\ + {html_body}\ +
\ +
" ), ) } @@ -98,8 +94,8 @@ mod tests { use super::OriginalRoomMessageEvent; #[test] - fn plain_quote_fallback_multiline() { - let (plain_quote, _html_quote) = + fn fallback_multiline() { + let (plain_quote, html_quote) = super::get_message_quote_fallbacks(&OriginalRoomMessageEvent { content: RoomMessageEventContent::text_plain("multi\nline"), event_id: event_id!("$1598361704261elfgc:localhost").to_owned(), @@ -110,5 +106,16 @@ mod tests { }); assert_eq!(plain_quote, "> <@alice:example.com> multi\n> line"); + assert_eq!( + html_quote, + "\ +
\ + In reply to \ + @alice:example.com\ +
\ + multi\nline\ +
\ +
" + ); } }