Skip to content

Commit

Permalink
Fix storage error when keyexpr equals the configured strip_prefix (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
oteffahi authored Sep 3, 2024
1 parent a8de5bc commit 0a911f3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions plugins/zenoh-plugin-storage-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,16 @@ pub fn strip_prefix(
);
}

match key_expr.strip_prefix(prefix).as_slice() {
[stripped_key_expr] => {
if stripped_key_expr.is_empty() {
return Ok(None);
}
// `key_expr.strip_prefix` returns empty vec if `key_expr == prefix`,
// but also returns empty vec if `prefix` is not a prefix to `key_expr`.
// First case needs to be handled before calling `key_expr.strip_prefix`
if key_expr.as_str().eq(prefix.as_str()) {
return Ok(None);
}

OwnedKeyExpr::from_str(stripped_key_expr).map(Some)
}
match key_expr.strip_prefix(prefix).as_slice() {
// NOTE: `stripped_key_expr.is_empty()` should be impossible as "" is not a valid key expression
[stripped_key_expr] => OwnedKeyExpr::from_str(stripped_key_expr).map(Some),
_ => bail!("Failed to strip prefix < {} > from: {}", prefix, key_expr),
}
}
Expand Down

0 comments on commit 0a911f3

Please sign in to comment.