Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
client: fix invalid node name pattern regex (#14593)
Browse files Browse the repository at this point in the history
* client: fix invalid name pattern regex

* Update client/cli/src/commands/run_cmd.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* client: test node name is non-empty

* client: add more tests to is_node_name_valid

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
andresilva and ggwpez authored Jul 18, 2023
1 parent 8463ca3 commit 696d09b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ impl CliConfiguration for RunCmd {
/// Check whether a node name is considered as valid.
pub fn is_node_name_valid(_name: &str) -> std::result::Result<(), &str> {
let name = _name.to_string();

if name.is_empty() {
return Err("Node name cannot be empty")
}

if name.chars().count() >= crate::NODE_NAME_MAX_LENGTH {
return Err("Node name too long")
}
Expand All @@ -404,7 +409,7 @@ pub fn is_node_name_valid(_name: &str) -> std::result::Result<(), &str> {
return Err("Node name should not contain invalid chars such as '.' and '@'")
}

let invalid_patterns = r"^https?:\/\/";
let invalid_patterns = r"^https?:";
let re = Regex::new(invalid_patterns).unwrap();
if re.is_match(&name) {
return Err("Node name should not contain urls")
Expand Down Expand Up @@ -498,15 +503,23 @@ mod tests {

#[test]
fn tests_node_name_bad() {
assert!(is_node_name_valid("").is_err());
assert!(is_node_name_valid(
"very very long names are really not very cool for the ui at all, really they're not"
)
.is_err());
assert!(is_node_name_valid("Dots.not.Ok").is_err());
assert!(is_node_name_valid("http://visit.me").is_err());
assert!(is_node_name_valid("https://visit.me").is_err());
// NOTE: the urls below don't include a domain otherwise
// they'd get filtered for including a `.`
assert!(is_node_name_valid("http://visitme").is_err());
assert!(is_node_name_valid("http:/visitme").is_err());
assert!(is_node_name_valid("http:visitme").is_err());
assert!(is_node_name_valid("https://visitme").is_err());
assert!(is_node_name_valid("https:/visitme").is_err());
assert!(is_node_name_valid("https:visitme").is_err());
assert!(is_node_name_valid("www.visit.me").is_err());
assert!(is_node_name_valid("www.visit").is_err());
assert!(is_node_name_valid("hello\\world").is_err());
assert!(is_node_name_valid("visit.www").is_err());
assert!(is_node_name_valid("email@domain").is_err());
}
Expand Down

0 comments on commit 696d09b

Please sign in to comment.