Conversation
Implement comprehensive glob pattern matching with support for wildcards, character classes, brace expansion, recursive patterns, and escape sequences. Includes 150+ test cases covering all features and real-world use cases.
Pull Request Test Coverage Report for Build 1867Details
💛 - Coveralls |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 472d21b646
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for i = t_idx; i < t_len; i = i + 1 { | ||
| if match_impl(pattern, text, next_p, i + 1, true) { | ||
| return true |
There was a problem hiding this comment.
Restrict
**/ matching to path-segment boundaries
The ** branch currently tries every character offset in text (i + 1) without checking for / boundaries, so patterns that are documented as matching path segments can match inside a segment. For example, @glob.is_match("**/test", "mytest") will return true by jumping directly to the t in mytest, even though there is no directory separator. This breaks core glob accuracy for directory-style patterns like **/name and src/**/test/*.txt.
Useful? React with 👍 / 👎.
| let mut found_close = false | ||
| while i < p_len && not(found_close) { | ||
| let curr = Int::unsafe_to_char(pattern[i]) | ||
| if curr == ']' && i != start_idx + 1 && i != start_idx + 2 { |
There was a problem hiding this comment.
🔴 Character class closing ] detection fails for single-element non-negated classes like [a]
The condition i != start_idx + 2 at line 219 prevents ] from being recognized as a closing bracket when it appears at position start_idx + 2, even in non-negated character classes. This check is intended to allow ] as a literal first character in negated classes like [!]...] or [^]...], but it incorrectly also blocks the closing ] in non-negated single-element classes.
Root Cause and Impact
For a pattern like [a] (start_idx=0):
i = 1: processesaas a literal,ibecomes 2i = 2:curr = ']', but the checki != start_idx + 2evaluates to2 != 2= false, so]is NOT recognized as the closing bracket]is instead treated as a literal character to match againstibecomes 3, exceedingp_len(3), so the loop exits without finding a close- The "Find closing ]" loop at line 244 also starts at
i = 3 >= p_len, so it returnsNone match_char_classreturnsNone, and the caller at line 153 returnsfalse
Impact: Any single-element character class like [a], [5], [.], [/] will always fail to match, returning false regardless of input. The existing tests don't catch this because they all use multi-element classes like [abc] or ranges like [a-z] where ] appears at index ≥ 3.
The fix should make the start_idx + 2 exclusion conditional on negation:
if curr == ']' && i != start_idx + 1 && (not(negate) || i != start_idx + 2) {
| if curr == ']' && i != start_idx + 1 && i != start_idx + 2 { | |
| if curr == ']' && i != start_idx + 1 && (not(negate) || i != start_idx + 2) { |
Was this helpful? React with 👍 or 👎 to provide feedback.
This PR adds a comprehensive glob pattern matching package to the MoonBit standard library.
Features
*(zero or more chars),?(exactly one char)[abc],[a-z],[!abc],[^abc]{a,b,c}**(matches across directories)\to escape special charactersImplementation
/)Int::unsafe_to_charTesting
150+ test cases covering:
**patternsAll tests passing: 5572/5572
Zero warnings after
moon checkDocumentation
Includes comprehensive README.mbt.md with:
Examples