Skip to content

Commit

Permalink
fix url parsing in contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
CherryWorm committed Mar 28, 2022
1 parent 7f76452 commit 8fe5208
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions security-txt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ impl Display for Contact {

impl Contact {
pub fn from_str(s: &str) -> Result<Self, SecurityTxtError> {
let parts: Vec<_> = s.split(":").collect();
if parts.len() != 2 {
return Err(SecurityTxtError::InvalidContact(s.to_string()));
}
let (contact_type, contact_info) = (parts[0].trim(), parts[1].trim());
let (typ, value) = s
.split_once(":")
.ok_or_else(|| SecurityTxtError::InvalidContact(s.to_string()))?;
let (contact_type, contact_info) = (typ.trim(), value.trim());
match contact_type.to_ascii_lowercase().as_str() {
"email" => Ok(Contact::Email(contact_info.to_string())),
"discord" => Ok(Contact::Discord(contact_info.to_string())),
Expand Down

0 comments on commit 8fe5208

Please sign in to comment.