micromatch / micromatch/picomatch
Kleene star on braces not working as intended
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.3k
- Forks
- 135
- Avg merge
- 23h 38m
- Merged PRs (30d)
- 7
Description
(Note that this does not have anything to do with the braces library).
From my reading of the code, it seems that there's an intent for braces to support the Kleene star (match zero or more times). In fact, one of the tests for braces is titled "should support Kleene stars" (see https://github.com/micromatch/picomatch/blob/master/test/braces.js#L50-L65). However, the way the tests are written, the assertions are ambiguous. The assertions succeed even if the star is interpreted as a glob.
Here's an example of one of the tests:
assert(isMatch('abcc', '{ab,c}*'))
That succeeds not because the pattern is repeated, but because the trailing * matches any characters after the match. To make the test unambiguous, we need a negative assertion.
assert(!isMatch('abcd', '{ab,c}*'))
If we examine the regular expression that picomatch generates, we see a discrepancy between a Kleene star and a Kleene plus.
makeRe('{ab,c}+', { strictSlashes: true })
// => /^(?:(ab|c)+)$/
makeRe('{ab,c}*', { strictSlashes: true })
// => /^(?:(ab|c)[^/]*?)$/
In the latter case, I expect the regular expression to be as follows:
/^(?:(ab|c)*)$/
None of the options I tried seem to affect the result.
I would hope that the Kleene star could be supported for braces. That would make them a parallel alternative to the inverted pattern of the extglob (e.g., *({ab,c})).
Note that since braces become parens, the intent to support the Kleene star seems to then contradict the following test: https://github.com/micromatch/picomatch/blob/master/test/parens.js#L7-L16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the brace tests in test/braces.js, especially the “should support Kleene stars” cases, and compare them with test/parens.js. Reproduce the issue with isMatch('{ab,c}*') and inspect makeRe output using strictSlashes: true. Done means the intended brace-star behavior is unambiguous and covered by positive and negative assertions without contradicting the paren behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100