Skip to content

Commit

Permalink
Check for the special case of the root facet as prefix of other facet…
Browse files Browse the repository at this point in the history
…s. (#1448)
  • Loading branch information
adamreichold authored Aug 19, 2022
1 parent 19074e1 commit 27400c9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/schema/facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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("/")));
}
}

0 comments on commit 27400c9

Please sign in to comment.