olson-sean-k / wax

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

Traverses directory boundaries when performing negative matching #40

Closed arlyon closed 1 year ago

arlyon commented 1 year ago

Hi!

I have noticed surprising behaviour when running a set of integration tests that I put together against micromatch (a javascript glob algorithm). I am on board with almost all of the changes, except one, and I wanted to make sure it was a bug before diving into the code to 'fix' it.

When presented with the glob a[!b]c, wax will happily match path separators in place of b which is odd. So, a/c passes that test case.

    #[test]
    fn negative_match_does_not_traverse_folders() {
        let glob = Glob::new("a[!b]c").unwrap();
        assert!(glob.is_match(Path::new("adc")));
        assert!(!glob.is_match(Path::new("a/c")));
    }

Compare this to a glob playground:

https://www.digitalocean.com/community/tools/glob?comments=true&glob=a%5B%21b%5Dc&matches=false&tests=%2F%2F%20expected&tests=adc&tests=%2F%2F%20wax%20fails%20here&tests=a%2Fc

arlyon commented 1 year ago

Some more context; a[!b]c ends up as a([^b&&[^/]])c which according to regex101 will fail. Looks like ([^b&&[^/]]) is invalid.

olson-sean-k commented 1 year ago

Thanks for reporting this! Yep, this is definitely a bug! I know it's been some time, but I just left some comments on your PR to fix this.