Skip to content

Commit 3d461a1

Browse files
committed
ensure brackets are matched
1 parent abcf341 commit 3d461a1

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/parse.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const parse = (input, options = {}) => {
4343
let stack = [ast];
4444
let block = ast;
4545
let prev = ast;
46+
let brackets = 0;
4647
let length = input.length;
4748
let index = 0;
4849
let depth = 0;
@@ -108,25 +109,31 @@ const parse = (input, options = {}) => {
108109
*/
109110

110111
if (value === CHAR_LEFT_SQUARE_BRACKET) {
112+
brackets++;
113+
111114
let closed = true;
112115
let next;
113116

114117
while (index < length && (next = advance())) {
115118
value += next;
116119

120+
if (next === CHAR_LEFT_SQUARE_BRACKET) {
121+
brackets++;
122+
continue;
123+
}
124+
117125
if (next === CHAR_BACKSLASH) {
118126
value += advance();
119127
continue;
120128
}
121129

122130
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
123-
closed = true;
124-
break;
125-
}
126-
}
131+
brackets--;
127132

128-
if (closed !== true) {
129-
value = '\\' + value;
133+
if (brackets === 0) {
134+
break;
135+
}
136+
}
130137
}
131138

132139
push({ type: 'text', value });

test/regression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ describe('bash tests', () => {
289289
equal('a/**/c/{d,e}/f*.{md,txt}', ['a/**/c/d/f*.md', 'a/**/c/d/f*.txt', 'a/**/c/e/f*.md', 'a/**/c/e/f*.txt']);
290290
});
291291

292-
it('should expand with extglobs.', () => {
292+
it('should expand with brackets.', () => {
293293
equal('a/b/{d,e,[1-5]}/*.js', ['a/b/d/*.js', 'a/b/e/*.js', 'a/b/[1-5]/*.js']);
294294
});
295295
});

0 commit comments

Comments
 (0)