Skip to content

Commit

Permalink
fix(23): properly parsing regex as Option<Regex> (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrik authored Dec 8, 2023
1 parent aaffebf commit 1919225
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions zenoh-plugin-mqtt/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,17 @@ fn deserialize_regex<'de, D>(deserializer: D) -> Result<Option<Regex>, D::Error>
where
D: Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
Regex::new(&s)
.map(Some)
.map_err(|e| de::Error::custom(format!("Invalid regex 'allow={s}': {e}")))
let s: Option<String> = Deserialize::deserialize(deserializer)?;

match s {
Some(s) => Regex::new(&s).map(Some).map_err(|e| {
de::Error::custom(format!(
r#"Invalid regex for 'allow' or 'deny': "{s}" - {e}"#
))
}),

None => Ok(None),
}
}

fn serialize_allow<S>(v: &Option<Regex>, serializer: S) -> Result<S::Ok, S::Error>
Expand Down

0 comments on commit 1919225

Please sign in to comment.