From 23c60d485903cc52f3a7cfdb4903a60e5899bddd Mon Sep 17 00:00:00 2001 From: Michael Flaherty Date: Wed, 20 Apr 2022 17:00:53 -0700 Subject: [PATCH 1/2] Fix args endpoint detection on replies --- src/utls/parser.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utls/parser.rs b/src/utls/parser.rs index f5030f6..cab169f 100644 --- a/src/utls/parser.rs +++ b/src/utls/parser.rs @@ -41,7 +41,7 @@ pub async fn get_components(input: &str, author : &User, compilation_manager : O let mut result = ParserResult::default(); // Find the index for where we should stop parsing user input - let mut end_point: usize = 0; + let mut end_point: usize = input.len(); if let Some(parse_stop) = input.find("\n") { end_point = parse_stop; } @@ -53,10 +53,7 @@ pub async fn get_components(input: &str, author : &User, compilation_manager : O else if index < end_point { end_point = index; } - } else { - end_point = input.len(); } - let mut args: Vec<&str> = input[..end_point].split_whitespace().collect(); // ditch command str (;compile, ;asm) args.remove(0); From 7643ffe4d2a35574b619bdeb27f25f5324b461e7 Mon Sep 17 00:00:00 2001 From: Michael Flaherty Date: Wed, 20 Apr 2022 17:12:03 -0700 Subject: [PATCH 2/2] Add test --- src/tests/parser.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tests/parser.rs b/src/tests/parser.rs index b9e7528..1003071 100644 --- a/src/tests/parser.rs +++ b/src/tests/parser.rs @@ -78,6 +78,29 @@ async fn standard_parse_url() { assert_eq!(parser_result.code, "int main() {}"); } +#[tokio::test] +async fn standard_parse_url_args() { + let dummy_user = User::default(); + let input = indoc::indoc!( + ";compile c++ < https://pastebin.com/raw/ERqDRZva\ntest1 test2" + ); + + let reply = None; + let result = get_components(input, &dummy_user, None, &reply).await; + if let Err(_) = &result { + assert!(false, "Parser failed."); + } + + let parser_result = result.unwrap(); + println!("{:?}", &parser_result); + assert_eq!(parser_result.target, "c++"); + assert_eq!(parser_result.args, ["test1", "test2"]); + assert_eq!(parser_result.options.len(), 0); + assert_eq!(parser_result.stdin, ""); + assert_eq!(parser_result.url, "https://pastebin.com/raw/ERqDRZva"); + assert_eq!(parser_result.code, "int main() {}"); +} + #[tokio::test] async fn standard_parse_stdin() { let dummy_user = User::default();