Check for the special case of the root facet as prefix of other facets. (#1448)

This commit is contained in:
Adam Reichold
2022-08-19 10:45:14 +02:00
committed by GitHub
parent 19074e1d5e
commit 27400c9ad3
+15 -1
View File
@@ -156,7 +156,7 @@ impl Facet {
let other_str = other.encoded_str();
self_str.len() < other_str.len()
&& other_str.starts_with(self_str)
&& other_str.as_bytes()[self_str.len()] == FACET_SEP_BYTE
&& (self_str.len() == 0 || other_str.as_bytes()[self_str.len()] == FACET_SEP_BYTE)
}
/// Extract path from the `Facet`.
@@ -301,4 +301,18 @@ mod tests {
Facet::from_text("INVALID")
);
}
#[test]
fn only_proper_prefixes() {
assert!(Facet::from("/foo").is_prefix_of(&Facet::from("/foo/bar")));
assert!(!Facet::from("/foo/bar").is_prefix_of(&Facet::from("/foo/bar")));
}
#[test]
fn root_is_a_prefix() {
assert!(Facet::from("/").is_prefix_of(&Facet::from("/foobar")));
assert!(!Facet::from("/").is_prefix_of(&Facet::from("/")));
}
}