mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-30 22:43:48 +03:00
Merge branch 'parse-pdu-command-panic' into 'next'
fix: do not panic on a JSON not containing the PDU Closes #236 See merge request famedly/conduit!304
This commit is contained in:
commit
0c4b42ac13
1 changed files with 18 additions and 16 deletions
|
@ -354,13 +354,9 @@ fn process_admin_command(
|
||||||
let string = body[1..body.len() - 1].join("\n");
|
let string = body[1..body.len() - 1].join("\n");
|
||||||
match serde_json::from_str(&string) {
|
match serde_json::from_str(&string) {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let event_id = EventId::parse(format!(
|
match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) {
|
||||||
"${}",
|
Ok(hash) => {
|
||||||
// Anything higher than version3 behaves the same
|
let event_id = EventId::parse(format!("${}", hash));
|
||||||
ruma::signatures::reference_hash(&value, &RoomVersionId::V6)
|
|
||||||
.expect("ruma can calculate reference hashes")
|
|
||||||
))
|
|
||||||
.expect("ruma's reference hashes are valid event ids");
|
|
||||||
|
|
||||||
match serde_json::from_value::<PduEvent>(
|
match serde_json::from_value::<PduEvent>(
|
||||||
serde_json::to_value(value).expect("value is json"),
|
serde_json::to_value(value).expect("value is json"),
|
||||||
|
@ -375,6 +371,12 @@ fn process_admin_command(
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
|
"Could not parse PDU JSON: {:?}",
|
||||||
|
e
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => RoomMessageEventContent::text_plain(format!(
|
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||||
"Invalid json in command body: {}",
|
"Invalid json in command body: {}",
|
||||||
e
|
e
|
||||||
|
|
Loading…
Reference in a new issue