Skip to content

Commit

Permalink
Fix #26634 - if a ./ include pattern contains glob characters, igno…
Browse files Browse the repository at this point in the history
…re the `./`
  • Loading branch information
roblourens committed May 24, 2017
1 parent 31aaf87 commit 70c10c9
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/vs/workbench/parts/search/browser/patternInputWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,24 @@ export class PatternInputWidget extends Widget {
return {};
}

const isSearchPath = segment => segment.match(/^\.\//);

let exprSegments: string[];
let searchPaths: string[];
if (isGlobPattern) {
const segments = splitGlobAware(pattern, ',')
.map(s => s.trim())
.filter(s => !!s.length);

const groups = collections.groupBy(segments,
segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments');
searchPaths = groups.searchPaths || [];
exprSegments = groups.exprSegments || [];
const groups = this.groupByPathsAndExprSegments(segments);
searchPaths = groups.searchPaths;
exprSegments = groups.exprSegments;
} else {
const segments = pattern.split(',')
.map(s => strings.trim(s.trim(), '/'))
.filter(s => !!s.length);

const groups = collections.groupBy(segments,
segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments');
searchPaths = groups.searchPaths || [];
exprSegments = groups.exprSegments || [];

exprSegments = exprSegments
const groups = this.groupByPathsAndExprSegments(segments);
searchPaths = groups.searchPaths;
exprSegments = groups.exprSegments
.map(p => {
if (p[0] === '.') {
p = '*' + p; // convert ".js" to "*.js"
Expand All @@ -147,6 +141,27 @@ export class PatternInputWidget extends Widget {
return { expression, searchPaths };
}

private groupByPathsAndExprSegments(segments: string[]) {
const isSearchPath = segment => segment.match(/^\.\//);

const groups = collections.groupBy(segments,
segment => isSearchPath(segment) ? 'searchPaths' : 'exprSegments');
groups.searchPaths = groups.searchPaths || [];
groups.exprSegments = groups.exprSegments || [];

// If a ./searchPath has a glob character, remove ./ and use it as an expression segment
groups.searchPaths = groups.searchPaths.filter(searchPath => {
if (searchPath.match(/[\*\{\}\(\)\[\]\?]/)) {
groups.exprSegments.push(strings.ltrim(searchPath, './'));
return false;
}

return true;
});

return groups;
}

public select(): void {
this.inputBox.select();
}
Expand Down

0 comments on commit 70c10c9

Please sign in to comment.