From 863473cdcb29d9989c39b4ff96bd54e14b13c6b6 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 4 Sep 2023 02:27:12 +0800 Subject: bugfix: last character of response message is truncated --- src/client.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs index 1e2edc4..3fcf78f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -57,14 +57,15 @@ pub async fn handle_client( } if b == b'\n' && prev_is_cr { if i < msg.len() { - i -= 2; // remove CRLF from reported message string + i -= 1; // remove CRLF from reported message string } break; } i += 1; prev_is_cr = b == b'\r'; } - let msg = match std::str::from_utf8(&msg[..i]) { + let msg = if i < msg.len() { &msg[..i] } else { &msg }; + let msg = match std::str::from_utf8(msg) { Ok(s) => s, Err(why) => { warn!( -- cgit v1.2.3