Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage error when keyexpr equals the configured strip_prefix #1351

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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