Skip to content

Commit

Permalink
fix unwrap error in maxmind rule matching
Browse files Browse the repository at this point in the history
Signed-off-by: yuguorui <[email protected]>
  • Loading branch information
yuguorui committed Jan 16, 2025
1 parent 54e3a8d commit 99c5091
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ impl Condition {
if let Some(reader) = ip_db {
let region: Result<maxminddb::geoip2::Country, maxminddb::MaxMindDBError> =
reader.lookup(dst_ip);
if let Ok(region) = region {
if self.maxmind_regions.contains(
&region
.country
.unwrap()
.iso_code
.unwrap()
.to_string()
.to_lowercase(),
) {
return true;
let isocode = region.and_then(|r| Ok(r.country.and_then(|c| c.iso_code)));
match isocode {
Ok(Some(isocode)) => {
if self
.maxmind_regions
.contains(&isocode.to_string().to_lowercase())
{
return true;
}
}
_ => {}
}
}
return false;
Expand Down

0 comments on commit 99c5091

Please sign in to comment.