Skip to content

Commit 54f9f49

Browse files
committed
add port range validation
1 parent 3fc1961 commit 54f9f49

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

oryx-tui/src/section/metrics.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,20 @@ impl UserInput {
6464
}),
6565
Err(_) => {
6666
let Some(caps) = re.captures(self.input.value()) else {
67-
self.error = Some("Invalid Port --".to_string());
67+
self.error = Some("Invalid Port(s)".to_string());
6868
return Err("Validation Error".into());
6969
};
70-
Ok(Range {
71-
start: caps["start"].parse()?,
72-
end: caps["end"].parse()?,
73-
})
70+
71+
let start: u16 = caps["start"].parse()?;
72+
let end: u16 = caps["end"].parse()?;
73+
74+
// Empty range
75+
if start >= end {
76+
self.error = Some("Invalid Port Range".to_string());
77+
return Err("Validation Error".into());
78+
}
79+
80+
Ok(Range { start, end })
7481
}
7582
}
7683
}
@@ -397,7 +404,7 @@ impl Metrics {
397404
//TODO: Center
398405
let rows = [
399406
Row::new(vec![
400-
Cell::from("Packet Counter".to_string())
407+
Cell::from("Port Packet Counter".to_string())
401408
.bg(Color::DarkGray)
402409
.fg(Color::White),
403410
Cell::from(self.user_input.input.value())

0 commit comments

Comments
 (0)