diff --git a/src/vs/base/common/glob.ts b/src/vs/base/common/glob.ts index d72e797c0270b49097a5e810e4fb94ab6c36d05d..bc0660ec85764fd6cffb7d5d6aee24572ffeb1dd 100644 --- a/src/vs/base/common/glob.ts +++ b/src/vs/base/common/glob.ts @@ -152,7 +152,7 @@ function parseRegExp(pattern: string): string { } // Support brackets - if (char !== ']' && inBrackets) { + if (inBrackets && (char !== ']' || !bracketVal) /* ] is literally only allowed as first character in brackets to match it */) { let res: string; // range operator @@ -165,6 +165,12 @@ function parseRegExp(pattern: string): string { res = '^'; } + // glob split matching is not allowed within character ranges + // see http://man7.org/linux/man-pages/man7/glob.7.html + else if (char === GLOB_SPLIT) { + res = ''; + } + // anything else gets escaped else { res = strings.escapeRegExpCharacters(char); diff --git a/src/vs/base/test/node/glob.test.ts b/src/vs/base/test/node/glob.test.ts index 776cae86f591f38238b446fdde2415234d342c4b..702e20f36d8ee8876b99f1fc35083b3ead2cb392 100644 --- a/src/vs/base/test/node/glob.test.ts +++ b/src/vs/base/test/node/glob.test.ts @@ -468,13 +468,38 @@ suite('Glob', () => { assert(!glob.match(p, 'bar.5')); assert(glob.match(p, 'foo.f')); - p = 'foo.[0!^]'; + p = 'foo.[0!^*?]'; assert(!glob.match(p, 'foo.5')); assert(!glob.match(p, 'foo.8')); assert(glob.match(p, 'foo.0')); assert(glob.match(p, 'foo.!')); assert(glob.match(p, 'foo.^')); + assert(glob.match(p, 'foo.*')); + assert(glob.match(p, 'foo.?')); + + p = 'foo[/]bar'; + + assert(!glob.match(p, 'foo/bar')); + + p = 'foo.[[]'; + + assert(glob.match(p, 'foo.[')); + + p = 'foo.[]]'; + + assert(glob.match(p, 'foo.]')); + + p = 'foo.[][!]'; + + assert(glob.match(p, 'foo.]')); + assert(glob.match(p, 'foo.[')); + assert(glob.match(p, 'foo.!')); + + p = 'foo.[]-]'; + + assert(glob.match(p, 'foo.]')); + assert(glob.match(p, 'foo.-')); }); test('full path', function () {