Skip to content

Commit

Permalink
bring prefix_is in line with is_prefixed_by
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFluffy committed Jun 7, 2024
1 parent 63aac90 commit 866ed6a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/astria-core/src/primitive/v1/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ impl Denom {
pub fn prefix_is(&self, prefix: &str) -> bool {
// For the current implementation, the number of slashes in a prefix is equal to the number
// of segments + 1.
// So a "path/to" would be a prefix to `"path/to/denom"`, but `"path/to/"` would not
let number_of_slashes = prefix.chars().filter(|c| *c == '/').count();
let number_of_slashes = prefix
.strip_suffix('/')
.unwrap_or(prefix)
.chars()
.filter(|c| *c == '/')
.count();
if number_of_slashes.saturating_add(1) != self.prefix_segments.len() {
return false;
}
Expand Down Expand Up @@ -362,8 +366,8 @@ mod tests {
let input = "path/to/denom";
let denom = input.parse::<Denom>().unwrap();
assert!(denom.prefix_is("path/to"));
assert!(denom.prefix_is("path/to/"));
assert!(!denom.prefix_is("path/to/denom"));
assert!(!denom.prefix_is("path/to/"));
assert!(!denom.prefix_is("/path/to"));
assert!(!denom.prefix_is("/path/to/"));
}
Expand Down

0 comments on commit 866ed6a

Please sign in to comment.