Skip to content

Commit

Permalink
fix: fix canonization not updating &mut str length (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo authored Jul 23, 2024
1 parent c58fcdc commit 9408f74
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion commons/zenoh-keyexpr/src/key_expr/canon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Canonize for &mut str {
let bytes = unsafe { self.as_bytes_mut() };
let length = canonize(bytes);
bytes[length..].fill(b'\0');
*self = &mut core::mem::take(self)[..length];
}
}

Expand Down Expand Up @@ -166,6 +167,8 @@ fn canonizer() {

// &mut str remaining part is zeroed
let mut s = String::from("$*$*$*/hello/$*$*/bye/$*$*");
s.as_mut_str().canonize();
let mut s_mut = s.as_mut_str();
s_mut.canonize();
assert_eq!(s_mut, "*/hello/*/bye/*");
assert_eq!(s, "*/hello/*/bye/*\0\0\0\0\0\0\0\0\0\0\0");
}

0 comments on commit 9408f74

Please sign in to comment.