Skip to content

Commit

Permalink
fix(23): properly parsing regex as Option<Regex>
Browse files Browse the repository at this point in the history
Signed-off-by: gabrik <[email protected]>
  • Loading branch information
gabrik committed Dec 7, 2023
1 parent aaffebf commit 1dd7969
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions zenoh-plugin-mqtt/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ 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!("Invalid regex 'allow={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 1dd7969

Please sign in to comment.