Skip to content

Commit

Permalink
Avoid Panic when extracting country id for UIFN numbers (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael Costa <[email protected]>
  • Loading branch information
regismesquita and costaraphael authored Jun 7, 2023
1 parent 989054c commit 23640df
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/phone_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl<'a> Country<'a> {
}

pub fn id(&self) -> Option<country::Id> {
self.0.metadata(&DATABASE).map(|m| m.id().parse().unwrap())
self.0.metadata(&DATABASE).and_then(|m| m.id().parse().ok())
}
}

Expand All @@ -248,6 +248,11 @@ mod test {

#[test]
fn country_id() {
assert_eq!(
None,
parser::parse(None, "+80012340000").unwrap().country().id()
);

assert_eq!(
country::AU,
parser::parse(None, "+61406823897")
Expand Down

0 comments on commit 23640df

Please sign in to comment.