提交 d7c052f4 编写于 作者: B Benjamin Pasero

glob - be stricter about syntax

上级 6d6c6fea
......@@ -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);
......
......@@ -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 () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册