From 2ef23b213a6e669a26aa541adfe59e5f563904a9 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 21 Aug 2021 14:38:00 +0200 Subject: [PATCH] Consistent and escaped response in get_pdu 1. The fallback text of the get_pdu admin room command response message now contains the same text as the formatted_body content (namely, the json instead of Debug-formatting of a serde type). 2. The formatted_body content of the get_pdu response is now html-escaped. --- src/database/rooms.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 0f42235..68837f6 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -7,6 +7,7 @@ use crate::{pdu::PduBuilder, utils, Database, Error, PduEvent, Result}; use lru_cache::LruCache; use regex::Regex; use ring::digest; +use rocket::http::RawStr; use ruma::{ api::{client::error::ErrorKind, federation}, events::{ @@ -1006,16 +1007,19 @@ impl Rooms { } match pdu_json { Some(json) => { + let json_text = + serde_json::to_string_pretty(&json) + .expect("canonical json is valid json"); db.admin.send(AdminCommand::SendMessage( message::MessageEventContent::text_html( - format!("{}\n```json\n{:#?}\n```", + format!("{}\n```json\n{}\n```", if outlier { "PDU is outlier" - } else { "PDU was accepted"}, json), + } else { "PDU was accepted"}, json_text), format!("

{}

\n
{}\n
\n", if outlier { "PDU is outlier" - } else { "PDU was accepted"}, serde_json::to_string_pretty(&json).expect("canonical json is valid json")) + } else { "PDU was accepted"}, RawStr::new(&json_text).html_escape()) ), )); }