Skip to content

Commit

Permalink
Do not increment prefix upper bound if there are no tokens.
Browse files Browse the repository at this point in the history
This change fixes a bug wherein `Glob::partition` panics if the `Glob`
is empty and has no tokens. In this case,
`invariant_text_prefix_upper_bound` returns `1`, but should return `0`.
  • Loading branch information
olson-sean-k committed Oct 4, 2023
1 parent 1afcda8 commit 561a332
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,13 @@ mod tests {
assert_eq!(format!("{}", glob), "**");
}

#[test]
fn partition_empty_glob() {
let (prefix, glob) = Glob::new("").unwrap().partition();
assert_eq!(prefix, Path::new(""));
assert_eq!(format!("{}", glob), "");
}

#[test]
fn repartition_glob_with_variant_tokens() {
let (prefix, glob) = Glob::new("/root/**/file.ext").unwrap().partition();
Expand All @@ -1997,6 +2004,14 @@ mod tests {
assert_eq!(format!("{}", glob), "**/file.ext");
}

#[test]
fn repartition_empty_glob() {
let (_, glob) = Glob::new("").unwrap().partition();
let (prefix, glob) = glob.partition();
assert_eq!(prefix, Path::new(""));
assert_eq!(format!("{}", glob), "");
}

#[test]
fn query_glob_has_root() {
assert!(Glob::new("/root").unwrap().has_root());
Expand Down
3 changes: 2 additions & 1 deletion src/token/variance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use itertools::Itertools as _;
use std::borrow::Cow;
use std::cmp;
use std::collections::VecDeque;
use std::ops::{Add, Mul};

Expand Down Expand Up @@ -556,7 +557,7 @@ where
},
}
}
m + 1
m + cmp::min(m, 1)
}

/// Returns `true` if the token tree is exhaustive.
Expand Down

0 comments on commit 561a332

Please sign in to comment.