Skip to content

Commit 142b15f

Browse files
authored
Merge pull request #49 from jakub-ekkosense/master
Fixed set expansion when starting with a range operator
2 parents 977c75a + 9a446a8 commit 142b15f

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

lib/parse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ const parse = (input, options = {}) => {
246246
const open = block.nodes.shift();
247247
block.nodes = [open, { type: 'text', value: stringify(block) }];
248248
}
249+
block.invalid = false;
249250

250251
push({ type: 'comma', value });
251252
block.commas++;

test/bash-expanded-sets.js

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,94 @@ describe('bash - expanded brace sets', () => {
222222
['f{x,y{{g}}h', {}, ['f{x,y{{g}}h']],
223223
['a{b{c{d,e}f{x,y{}g}h', {}, ['a{b{cdfxh', 'a{b{cdfy{}gh', 'a{b{cefxh', 'a{b{cefy{}gh']],
224224
['f{x,y{}g}h', {}, ['fxh', 'fy{}gh']],
225-
['z{a,b{,c}d', {}, ['z{a,bd', 'z{a,bcd']]
225+
['z{a,b{,c}d', {}, ['z{a,bd', 'z{a,bcd']],
226+
227+
'should expand sets containing the range operator',
228+
229+
['{..a,b}', {}, ['..a', 'b']],
230+
['{b,..a}', {}, ['b', '..a']],
231+
['{a..,b}', {}, ['a..', 'b']],
232+
['{...,b}', {}, ['...', 'b']],
233+
['{a,..,b}', {}, ['a', '..', 'b']],
234+
['..{a,b}', {}, ['..a', '..b']],
235+
['{{..,..},a,b}', {}, ['..', '..', 'a', 'b']],
236+
['{{{..,..}a,b}c,d}', {}, ['..ac', '..ac', 'bc', 'd']],
237+
['..{..,{..,{..,..}a,b}c,d}', {}, ['....', '....c', '....ac', '....ac', '..bc', '..d']],
238+
['..', {}, ['..']],
239+
['{,..}', {}, ['', '..']],
240+
['{..,}', {}, ['..', '']],
241+
['{..,..,..}', {}, ['..', '..', '..']],
242+
['{...,..,..}', {}, ['...', '..', '..']],
243+
['{..,...,..}', {}, ['..', '...', '..']],
244+
['{./../.,../../}', {}, ['./../.', '../../']],
245+
['{../../../,../../}', {}, ['../../../', '../../']],
246+
['{...,...,...}', {}, ['...', '...', '...']],
247+
['{.,..,.}', {}, ['.', '..', '.']],
248+
[',{..,..,.},', {}, [',..,', ',..,', ',.,']],
249+
['{1..2,3..4}', {}, ['1..2', '3..4']],
250+
['{..2,3..4}', {}, ['..2', '3..4']],
251+
['{1..,2}', {}, ['1..', '2']],
252+
['{1..,..2..,..3}', {}, ['1..', '..2..', '..3']],
253+
['..{1..3}', {}, ['..1', '..2', '..3']],
254+
['..{1..3}{..,..}', {}, ['..1..', '..1..', '..2..', '..2..', '..3..', '..3..']],
255+
256+
'should not expand invalid sets containing the range operator',
257+
258+
['{..a,b', {}, ['{..a,b']],
259+
['{b,..a', {}, ['{b,..a']],
260+
['{a..,b', {}, ['{a..,b']],
261+
['{...,b', {}, ['{...,b']],
262+
['{a,..,b', {}, ['{a,..,b']],
263+
['..{a,b', {}, ['..{a,b']],
264+
['{{..,..},a,b', {}, ['{..,a,b', '{..,a,b']],
265+
['{{{..,..}a,b}c,d', {}, ['{..ac,d', '{..ac,d', '{bc,d']],
266+
['{{{..,..}a,bc,d}', {}, ['{..a', '{..a', '{bc', '{d']],
267+
['..{..,{..,{..,..}a,b}c,d', {}, ['..{..,..c,d', '..{..,..ac,d', '..{..,..ac,d', '..{..,bc,d']],
268+
['..', {}, ['..']],
269+
['{,..', {}, ['{,..']],
270+
['{..,', {}, ['{..,']],
271+
['{..,..,..', {}, ['{..,..,..']],
272+
['{...,..,..', {}, ['{...,..,..']],
273+
['{..,...,..', {}, ['{..,...,..']],
274+
['{./../.,../../', {}, ['{./../.,../../']],
275+
['{../../../,../../', {}, ['{../../../,../../']],
276+
['{...,...,...', {}, ['{...,...,...']],
277+
['{.,..,.', {}, ['{.,..,.']],
278+
[',{..,..,.},', {}, [',..,', ',..,', ',.,']],
279+
['{1..2,3..4', {}, ['{1..2,3..4']],
280+
['{..2,3..4', {}, ['{..2,3..4']],
281+
['{1..,2', {}, ['{1..,2']],
282+
['{1..,..2..,..3', {}, ['{1..,..2..,..3']],
283+
['..{1..3', {}, ['..{1..3']],
284+
['..{1..3}{..,..', {}, ['..1{..,..', '..2{..,..', '..3{..,..']],
285+
286+
['..a,b}', {}, ['..a,b}']],
287+
['b,..a}', {}, ['b,..a}']],
288+
['a..,b}', {}, ['a..,b}']],
289+
['...,b}', {}, ['...,b}']],
290+
['a,..,b}', {}, ['a,..,b}']],
291+
['..a,b}', {}, ['..a,b}']],
292+
['{..,..},a,b}', {}, ['..,a,b}', '..,a,b}']],
293+
['{{..,..}a,b}c,d}', {}, ['..ac,d}', '..ac,d}', 'bc,d}']],
294+
['....,{..,{..,..}a,b}c,d}', {}, ['....,..c,d}', '....,..ac,d}', '....,..ac,d}', '....,bc,d}']],
295+
['..', {}, ['..']],
296+
[',..}', {}, [',..}']],
297+
['..,}', {}, ['..,}']],
298+
['..,..,..}', {}, ['..,..,..}']],
299+
['...,..,..}', {}, ['...,..,..}']],
300+
['..,...,..}', {}, ['..,...,..}']],
301+
['./../.,../../}', {}, ['./../.,../../}']],
302+
['../../../,../../}', {}, ['../../../,../../}']],
303+
['...,...,...}', {}, ['...,...,...}']],
304+
['.,..,.}', {}, ['.,..,.}']],
305+
[',..,..,.},', {}, [',..,..,.},']],
306+
['1..2,3..4}', {}, ['1..2,3..4}']],
307+
['..2,3..4}', {}, ['..2,3..4}']],
308+
['1..,2}', {}, ['1..,2}']],
309+
['1..,..2..,..3}', {}, ['1..,..2..,..3}']],
310+
['..1..3}', {}, ['..1..3}']],
311+
['..1..3}{..,..}', {}, ['..1..3}..', '..1..3}..']],
312+
226313
];
227314

228315
fixtures.forEach(arr => {

0 commit comments

Comments
 (0)