Skip to content

Commit e688782

Browse files
authored
API: createFileSystemWatcher() doesn't work when relative path ends with / (fix microsoft#162498) (microsoft#166372)
1 parent edccbd1 commit e688782

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/vs/base/common/glob.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { isEqualOrParent } from 'vs/base/common/extpath';
1010
import { LRUCache } from 'vs/base/common/map';
1111
import { basename, extname, posix, sep } from 'vs/base/common/path';
1212
import { isLinux } from 'vs/base/common/platform';
13-
import { escapeRegExpCharacters } from 'vs/base/common/strings';
13+
import { escapeRegExpCharacters, ltrim } from 'vs/base/common/strings';
1414

1515
export interface IRelativePattern {
1616

@@ -367,7 +367,12 @@ function wrapRelativePattern(parsedPattern: ParsedStringPattern, arg2: string |
367367
// Given we have checked `base` being a parent of `path`,
368368
// we can now remove the `base` portion of the `path`
369369
// and only match on the remaining path components
370-
return parsedPattern(path.substr(arg2.base.length + 1), basename);
370+
// For that we try to extract the portion of the `path`
371+
// that comes after the `base` portion. We have to account
372+
// for the fact that `base` might end in a path separator
373+
// (https://github.com/microsoft/vscode/issues/162498)
374+
375+
return parsedPattern(ltrim(path.substr(arg2.base.length), sep), basename);
371376
};
372377

373378
// Make sure to preserve associated metadata

src/vs/base/test/common/glob.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,22 @@ suite('Glob', () => {
10911091
}
10921092
});
10931093

1094+
test('relative pattern - trailing slash / backslash (#162498)', function () {
1095+
if (isWindows) {
1096+
let p: glob.IRelativePattern = { base: 'C:\\', pattern: 'foo.cs' };
1097+
assertGlobMatch(p, 'C:\\foo.cs');
1098+
1099+
p = { base: 'C:\\bar\\', pattern: 'foo.cs' };
1100+
assertGlobMatch(p, 'C:\\bar\\foo.cs');
1101+
} else {
1102+
let p: glob.IRelativePattern = { base: '/', pattern: 'foo.cs' };
1103+
assertGlobMatch(p, '/foo.cs');
1104+
1105+
p = { base: '/bar/', pattern: 'foo.cs' };
1106+
assertGlobMatch(p, '/bar/foo.cs');
1107+
}
1108+
});
1109+
10941110
test('pattern with "base" does not explode - #36081', function () {
10951111
assert.ok(glob.match({ 'base': true }, 'base'));
10961112
});

src/vscode-dts/vscode.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,9 @@ declare module 'vscode' {
20662066
export class RelativePattern {
20672067

20682068
/**
2069-
* A base file path to which this pattern will be matched against relatively.
2069+
* A base file path to which this pattern will be matched against relatively. The
2070+
* file path must be absolute, should not have any trailing path separators and
2071+
* not include any relative segments (`.` or `..`).
20702072
*/
20712073
baseUri: Uri;
20722074

0 commit comments

Comments
 (0)