mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-08-18 12:08:22 +00:00
Check for the special case of the root facet as prefix of other facets. (#1448)
This commit is contained in:
+15
-1
@@ -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("/")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user