From 2a9e13cc7afcdb525f38e5cd199c83921c1c405d Mon Sep 17 00:00:00 2001 From: Duc Nghiem-Xuan Date: Wed, 19 Nov 2025 01:18:04 +0900 Subject: [PATCH] Fix suport for globstars at the start of patterns in braces Fixes #115 --- lib/parse.js | 11 +++++++++++ test/braces.js | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/parse.js b/lib/parse.js index 8fd8ff49..64f20450 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -897,6 +897,17 @@ const parse = (input, options) => { continue; } + if (isBrace && rest[0] === '/') { + prev.type = 'globstar'; + prev.value += value; + prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`; + state.output += prev.output; + state.globstar = true; + consume(value + advance()); + push({ type: 'slash', value: '/', output: '' }); + continue; + } + // remove single star from output state.output = state.output.slice(0, -prev.output.length); diff --git a/test/braces.js b/test/braces.js index a343c316..984794ab 100644 --- a/test/braces.js +++ b/test/braces.js @@ -146,6 +146,17 @@ describe('braces', () => { assert(isMatch('a/b/bar/baz.qux', 'a/b{,/**}/bar{,/**}/*.*')); }); + it('should support braces with globstars at the start of pattern', () => { + assert(isMatch('a.json', '{**/*.json,**/*.js}')); + assert(isMatch('a.js', '{**/*.json,**/*.js}')); + assert(isMatch('a/b.json', '{**/*.json,**/*.js}')); + assert(isMatch('a/b.js', '{**/*.json,**/*.js}')); + assert(isMatch('foo.md', '{**/foo.md,bar.md}')); + assert(isMatch('a/foo.md', '{**/foo.md,bar.md}')); + assert(isMatch('foo.md', '{bar.md,**/foo.md}')); + assert(isMatch('a/foo.md', '{**/foo.md,bar.md}')); + }); + it('should support Kleene plus', () => { assert(isMatch('ab', '{ab,c}+')); assert(isMatch('abab', '{ab,c}+'));