From 54f9f499c504ba7eccb60c9cbab3955b70f133f0 Mon Sep 17 00:00:00 2001 From: Badr Date: Wed, 15 Jan 2025 19:54:05 +0100 Subject: [PATCH] add port range validation --- oryx-tui/src/section/metrics.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/oryx-tui/src/section/metrics.rs b/oryx-tui/src/section/metrics.rs index f4f44f3..13c7e73 100644 --- a/oryx-tui/src/section/metrics.rs +++ b/oryx-tui/src/section/metrics.rs @@ -64,13 +64,20 @@ impl UserInput { }), Err(_) => { let Some(caps) = re.captures(self.input.value()) else { - self.error = Some("Invalid Port --".to_string()); + self.error = Some("Invalid Port(s)".to_string()); return Err("Validation Error".into()); }; - Ok(Range { - start: caps["start"].parse()?, - end: caps["end"].parse()?, - }) + + let start: u16 = caps["start"].parse()?; + let end: u16 = caps["end"].parse()?; + + // Empty range + if start >= end { + self.error = Some("Invalid Port Range".to_string()); + return Err("Validation Error".into()); + } + + Ok(Range { start, end }) } } } @@ -397,7 +404,7 @@ impl Metrics { //TODO: Center let rows = [ Row::new(vec![ - Cell::from("Packet Counter".to_string()) + Cell::from("Port Packet Counter".to_string()) .bg(Color::DarkGray) .fg(Color::White), Cell::from(self.user_input.input.value())