Skip to content

Commit d875e0c

Browse files
jevolkgirlbossceo
authored andcommitted
fix handling of empty admin command lines
Signed-off-by: Jason Volk <jason@zemos.net>
1 parent 7a71012 commit d875e0c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/admin/handler.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern crate conduit_service as service;
99

1010
use conduit::Result;
1111
pub(crate) use service::admin::{Command, Service};
12-
use service::admin::{CommandResult, HandlerResult};
12+
use service::admin::{CommandOutput, CommandResult, HandlerResult};
1313

1414
use self::{fsck::FsckCommand, tester::TesterCommands};
1515
use crate::{
@@ -68,7 +68,10 @@ pub fn handle(command: Command) -> HandlerResult { Box::pin(handle_command(comma
6868

6969
#[tracing::instrument(skip_all, name = "admin")]
7070
async fn handle_command(command: Command) -> CommandResult {
71-
let mut content = process_admin_message(command.command).await;
71+
let Some(mut content) = process_admin_message(command.command).await else {
72+
return Ok(None);
73+
};
74+
7275
content.relates_to = command.reply_id.map(|event_id| Reply {
7376
in_reply_to: InReplyTo {
7477
event_id,
@@ -79,7 +82,7 @@ async fn handle_command(command: Command) -> CommandResult {
7982
}
8083

8184
// Parse and process a message from the admin room
82-
async fn process_admin_message(msg: String) -> RoomMessageEventContent {
85+
async fn process_admin_message(msg: String) -> CommandOutput {
8386
let mut lines = msg.lines().filter(|l| !l.trim().is_empty());
8487
let command_line = lines.next().expect("each string has at least one line");
8588
let body = lines.collect::<Vec<_>>();
@@ -89,15 +92,15 @@ async fn process_admin_message(msg: String) -> RoomMessageEventContent {
8992
Err(error) => {
9093
let server_name = services().globals.server_name();
9194
let message = error.replace("server.name", server_name.as_str());
92-
return RoomMessageEventContent::notice_markdown(message);
95+
return Some(RoomMessageEventContent::notice_markdown(message));
9396
},
9497
};
9598

9699
match process_admin_command(admin_command, body).await {
97-
Ok(reply_message) => reply_message,
100+
Ok(reply_message) => Some(reply_message),
98101
Err(error) => {
99102
let markdown_message = format!("Encountered an error while handling the command:\n```\n{error}\n```",);
100-
RoomMessageEventContent::notice_markdown(markdown_message)
103+
Some(RoomMessageEventContent::notice_markdown(markdown_message))
101104
},
102105
}
103106
}

src/service/admin/console.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Console {
138138

139139
#[allow(clippy::let_underscore_must_use)]
140140
async fn handle(self: Arc<Self>, line: String) {
141-
if line.is_empty() {
141+
if line.trim().is_empty() {
142142
return;
143143
}
144144

0 commit comments

Comments
 (0)