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.
This commit is contained in:
parent
cefca2d0d1
commit
2ef23b213a
1 changed files with 7 additions and 3 deletions
|
@ -7,6 +7,7 @@ use crate::{pdu::PduBuilder, utils, Database, Error, PduEvent, Result};
|
||||||
use lru_cache::LruCache;
|
use lru_cache::LruCache;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use ring::digest;
|
use ring::digest;
|
||||||
|
use rocket::http::RawStr;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{client::error::ErrorKind, federation},
|
api::{client::error::ErrorKind, federation},
|
||||||
events::{
|
events::{
|
||||||
|
@ -1006,16 +1007,19 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
match pdu_json {
|
match pdu_json {
|
||||||
Some(json) => {
|
Some(json) => {
|
||||||
|
let json_text =
|
||||||
|
serde_json::to_string_pretty(&json)
|
||||||
|
.expect("canonical json is valid json");
|
||||||
db.admin.send(AdminCommand::SendMessage(
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
message::MessageEventContent::text_html(
|
message::MessageEventContent::text_html(
|
||||||
format!("{}\n```json\n{:#?}\n```",
|
format!("{}\n```json\n{}\n```",
|
||||||
if outlier {
|
if outlier {
|
||||||
"PDU is outlier"
|
"PDU is outlier"
|
||||||
} else { "PDU was accepted"}, json),
|
} else { "PDU was accepted"}, json_text),
|
||||||
format!("<p>{}</p>\n<pre><code class=\"language-json\">{}\n</code></pre>\n",
|
format!("<p>{}</p>\n<pre><code class=\"language-json\">{}\n</code></pre>\n",
|
||||||
if outlier {
|
if outlier {
|
||||||
"PDU is 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())
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue