olson-sean-k / wax

Opinionated and portable globs that can be matched against paths and directory trees.
https://glob.guide
MIT License
112 stars 10 forks source link

`Glob::partition` documentation incorrectly claims that `Glob` outputs are always unrooted. #47

Open olson-sean-k opened 11 months ago

olson-sean-k commented 11 months ago

At time of writing, the documentation for Glob::partition says:

Partitioned Globs are never rooted. If the glob expression has a root component, then it is always included in the invariant PathBuf prefix.

But this isn't true! There is at least one exception I'm aware of, which are expressions beginning with a rooted repetition. For example, </root:1,>.

let (path, glob) = Glob::new("</root:1,>").unwrap().partition();
assert!(glob.has_root()); // OK. `glob` has been partitioned but is still rooted!
olson-sean-k commented 11 months ago

Repetitions that occur at the beginning of a glob expression are the only example I can think of where this occurs. Note that rooted alternatives are forbidden at the beginning of an expression, so for example {/root} cannot occur at time of writing. However, that rule is intended to prevent overlapping trees and arguably alternatives at the beginning of an expression with only one rooting branch should be permitted.

So the documentation should be sure to mention the exception here: tree tokens (i.e., alternatives and repetitions) with roots at the beginning of an expression. Note also that when this occurs the path part is necessarily empty.