提交 5f05e3a6 编写于 作者: R Rob Lourens

Fix #32325, avoid **/** pattern in search glob

上级 c185e7d4
......@@ -106,7 +106,7 @@ export class QueryBuilder {
p = '*' + p; // convert ".js" to "*.js"
}
return strings.format('{**/{0}/**,**/{0}}', p); // convert foo to {foo/**,**/foo} to cover files and folders
return toGlobalGlob(p);
});
const result: ISearchPathsResult = {};
......@@ -297,3 +297,11 @@ function splitGlobPattern(pattern: string): string[] {
.map(s => s.trim())
.filter(s => !!s.length);
}
/**
* Avoid double ** pattern, see https://github.com/Microsoft/vscode/issues/32325
*/
function toGlobalGlob(pattern: string): string {
const globalGlob = strings.format('{**/{0}/**,**/{0}}', pattern); // convert foo to {**/foo/**,**/foo} to cover files and folders
return globalGlob.replace(/\*\*([/\\]\*\*)+/g, '**');
}
......@@ -294,7 +294,7 @@ suite('QueryBuilder', () => {
[ROOT_1_URI],
{
extraFileResources: [getUri('/foo/bar.js')],
excludePattern: '**/*.js'
excludePattern: '*.js'
}
),
<ISearchQuery>{
......@@ -302,7 +302,7 @@ suite('QueryBuilder', () => {
folderQueries: [{
folder: ROOT_1_URI
}],
excludePattern: patternsToIExpression(globalGlob('**/*.js')),
excludePattern: patternsToIExpression(globalGlob('*.js')),
type: QueryType.Text,
useRipgrep: true
});
......@@ -313,7 +313,7 @@ suite('QueryBuilder', () => {
[ROOT_1_URI],
{
extraFileResources: [getUri('/foo/bar.js')],
includePattern: '**/*.txt'
includePattern: '*.txt'
}
),
<ISearchQuery>{
......@@ -321,7 +321,7 @@ suite('QueryBuilder', () => {
folderQueries: [{
folder: ROOT_1_URI
}],
includePattern: patternsToIExpression(globalGlob('**/*.txt')),
includePattern: patternsToIExpression(globalGlob('*.txt')),
type: QueryType.Text,
useRipgrep: true
});
......@@ -348,6 +348,24 @@ suite('QueryBuilder', () => {
].forEach(([includePattern, expectedPatterns]) => testSimpleIncludes(<string>includePattern, <string[]>expectedPatterns));
});
test('double-star patterns are normalized', () => {
function testLiteralIncludes(includePattern: string, expectedPattern: string): void {
assert.deepEqual(
queryBuilder.parseSearchPaths(includePattern),
<ISearchPathsResult>{
pattern: patternsToIExpression(expectedPattern)
},
includePattern);
}
[
['**/*.*', '{**/*.*/**,**/*.*}'],
['foo/**', '{**/foo/**,**/foo/**}'],
['**/**/foo', '{**/foo/**,**/foo}'],
['**/**', '{**,**}']
].forEach(([includePattern, expectedPattern]) => testLiteralIncludes(includePattern, expectedPattern));
});
function testIncludes(includePattern: string, expectedResult: ISearchPathsResult): void {
assertEqualSearchPathResults(
queryBuilder.parseSearchPaths(includePattern),
......@@ -645,7 +663,8 @@ function cleanUndefinedQueryValues(q: any): void {
}
function globalGlob(str: string): string {
return `{**/${str}/**,**/${str}}`;
const globalGlob = `{**/${str}/**,**/${str}}`;
return globalGlob.replace(/\*\*([/\\]\*\*)+/g, '**');
}
function patternsToIExpression(...patterns: string[]): IExpression {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册