Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d461a1

Browse files
committed
ensure brackets are matched
1 parentabcf341 commit3d461a1

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
letstack=[ast];
4444
letblock=ast;
4545
letprev=ast;
46+
letbrackets=0;
4647
letlength=input.length;
4748
letindex=0;
4849
letdepth=0;
@@ -108,25 +109,31 @@ const parse = (input, options = {}) => {
108109
*/
109110

110111
if(value===CHAR_LEFT_SQUARE_BRACKET){
112+
brackets++;
113+
111114
letclosed=true;
112115
letnext;
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 withextglobs.',()=>{
292+
it('should expand withbrackets.',()=>{
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)

[8]ページ先頭

©2009-2026 Movatter.jp