Repository navigation
glob: stop a non-segment ** from swallowing the ** segments after it in match()
#38996
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,8 +132,9 @@ struct Wildcard { | |
| /// Matches zero or more characters, except for path separators ('/' or '\'). | ||
| /// "**" | ||
| /// Matches zero or more characters, including path separators. | ||
| /// Must match a complete path segment, i.e. followed by a path separator or | ||
| /// at the end of the pattern. | ||
| /// Must be a complete path segment, i.e. preceded by a path separator (or | ||
| /// the start of the pattern) and followed by one (or the end of the | ||
| /// pattern). Anywhere else ("a**") it behaves like "*". | ||
| /// "[ab]" | ||
| /// Matches one of the characters contained in the brackets. | ||
| /// Character ranges (e.g. "[a-z]") are also supported. | ||
|
|
@@ -199,8 +200,18 @@ fn glob_match_impl( | |
| 'to_else: { | ||
| match ch { | ||
| b'*' => { | ||
| // `**` is a globstar only at the start of a segment: after a `/` | ||
| // or at `glob_start` (the pattern or, as in `{**/a,**/b}`, the | ||
| // brace branch; `<=` because backtracking out of a branch can | ||
| // land before its start). Anywhere else (`a**`) each `*` is a | ||
| // plain wildcard, and this must be decided before | ||
| // `skip_globstars` folds any following `/**` segments into this | ||
| // one: those belong to the rest of the pattern when this `**` | ||
| // is not a globstar (`a**/**` means `a*/**`). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| let is_globstar = (state.glob_index as usize) + 1 < glob.len() | ||
| && glob[state.glob_index as usize + 1] == b'*'; | ||
| && glob[state.glob_index as usize + 1] == b'*' | ||
| && (state.glob_index <= glob_start | ||
| || glob[state.glob_index as usize - 1] == b'/'); | ||
| if is_globstar { | ||
| skip_globstars(glob, &mut state.glob_index); | ||
| } | ||
|
|
@@ -232,13 +243,7 @@ fn glob_match_impl( | |
| continue 'main_loop; | ||
| } | ||
|
|
||
| // subtract glob_start from glob index before checking if length is less than 3. Given the pattern: | ||
| // {**/a,**/b} | ||
| // if we start at index 6 (start of **/b pattern), we don't want to index into the pattern before it | ||
| if (state.glob_index.saturating_sub(glob_start) < 3 | ||
| || glob[state.glob_index as usize - 3] == b'/') | ||
| && (!is_end_invalid || glob[state.glob_index as usize] == b'/') | ||
| { | ||
| if !is_end_invalid || glob[state.glob_index as usize] == b'/' { | ||
| if is_end_invalid { | ||
| state.glob_index += 1; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code