Skip to content

Commit

Permalink
fix: trim whitespace from conversation names before validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bytesoverflow committed Nov 7, 2024
1 parent 9f91859 commit dd479f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ pub fn read_user_input() -> String {

// Validate the conversation name
pub fn valid_conversation_name(s: &str) -> Result<String, String> {
let trimmed = s.trim();
let re = Regex::new(r"^[a-zA-Z0-9_-]+$").unwrap();
if re.is_match(s) {
Ok(s.to_string())
if re.is_match(trimmed) {
Ok(trimmed.to_string())
} else {
Err(format!("Invalid conversation name: {}. Use only letters, numbers, underscores, and hyphens.", s))
Err(format!("Invalid conversation name: {}. Use only letters, numbers, underscores, and hyphens.", trimmed))
}
}

0 comments on commit dd479f6

Please sign in to comment.