Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🚑 pattern with globstar and star fails to match #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,21 @@ fn glob_match_internal<'a>(
state.path_index += 1;

// If this is not a separator, lock in the previous globstar.
if c != b'/' {
if c != b'/'
&& (state.globstar.glob_index <= 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glob_index will never less than 0

&& (
// starts with a globstar
glob.len() > 1
&& glob[state.globstar.glob_index as usize] != b'*'
&& (glob[state.globstar.glob_index as usize + 1] != b'*')
|| (
// or the globstar state equals the wildcard state
state.globstar.glob_index == state.wildcard.glob_index as u32
&& state.globstar.path_index == state.wildcard.path_index as u32
&& state.globstar.capture_index == state.wildcard.capture_index as u32
)
))
{
state.globstar.path_index = 0;
}
continue;
Expand Down Expand Up @@ -626,6 +640,16 @@ mod tests {
assert!(!glob_match("a/{a{a,b},b}", "a/c"));
assert!(glob_match("a/{b,c[}]*}", "a/b"));
assert!(glob_match("a/{b,c[}]*}", "a/c}xx"));

assert!(glob_match("/**/*a", "/a/a"));
assert!(glob_match("**/*.js", "a/b.c/c.js"));
assert!(glob_match("**/**/*.js", "a/b.c/c.js"));
assert!(glob_match("a/**/*.d", "a/b/c.d"));
assert!(glob_match("a/**/*.d", "a/.b/c.d"));

// still not working
// assert!(glob_match("**/*/**", "a/b/c"));
// assert!(glob_match("**/*/c.js", "a/b/c.js"));;
}

// The below tests are based on Bash and micromatch.
Expand Down