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

Kleene star on braces not working as intended #97

Open
mojavelinux opened this issue Nov 3, 2021 · 0 comments
Open

Kleene star on braces not working as intended #97

mojavelinux opened this issue Nov 3, 2021 · 0 comments

Comments

@mojavelinux
Copy link
Contributor

mojavelinux commented Nov 3, 2021

(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant